Search.../

le( )

Creates a search filter for matching documents whose specified field value is less than or equal to the specified value.

Description

The ge() function is chained to a WixSearchFilterBuilder to create a WixSearchFilter. You can use the filter to match documents where the value of the specified field is less than or equal to the specified value.

le() only matches values of the same type. For example, a number value stored as a String type does not match the same number stored as a Number type.

If a field contains a number as a String, that value will be compared alphabetically and not numerically. Documents that do not have a value for the specified field are ranked lowest.

The following types of fields can be compared:

  • Number: Compares numerically.
  • Date: Compares JavaScript Date objects.
  • String: Compares lexicographically, so "Text" is less than or equal to "text" (because of the 'less than').

Syntax

function le(field: string, value: string | number | Date): WixSearchFilter

le Parameters

NAME
TYPE
DESCRIPTION
field
string

The field whose value will be compared with value.

value
string | number | Date

The value to match against.

Returns

A WixSearchFilter object.

Return Type:

WixSearchFilter
NAME
TYPE
DESCRIPTION
filterDefinition
Object

An object containing the filter definition.

Was this helpful?

Create a less than or equals search filter

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5const leFilter = wixSearch
6 .filter()
7 .le("viewCount", 50);
Create less than or equals search filters and add them to a search

This example demonstrates how to search for unpopular forum posts that have either a small amount of comments, views, or likes. The filters are joined and chained to a search using an or() filtering function.

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5const leCommentFilter = wixSearch
6 .filter()
7 .le("totalComments", 5)
8
9const leViewFilter = wixSearch
10 .filter()
11 .le("viewCount", 20)
12
13const leLikeFilter = wixSearch
14 .filter()
15 .le("likeCount", 3)
16
17
18wixSearch.search()
19 .documentType("Forum/Content")
20 .or(leCommentFilter, leViewFilter, leLikeFilter)
21 .find()
22 .then( (results) => {
23 if(results.documents.length > 0) {
24 let documents = results.documents;
25 } else {
26 console.log("No matching results");
27 }
28 })
29 .catch( (error) => {
30 console.log(error);
31 });
32
33