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
The field whose value will be compared with value
.
The value to match against.
Returns
A WixSearchFilter
object.
Return Type:
NAME
TYPE
DESCRIPTION
An object containing the filter definition.
Was this helpful?
1import wixSearch from 'wix-search';23// ...45const leFilter = wixSearch6 .filter()7 .le("viewCount", 50);
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.
1import wixSearch from 'wix-search';23// ...45const leCommentFilter = wixSearch6 .filter()7 .le("totalComments", 5)89const leViewFilter = wixSearch10 .filter()11 .le("viewCount", 20)1213const leLikeFilter = wixSearch14 .filter()15 .le("likeCount", 3)161718wixSearch.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 });3233