Search.../

gt( )

Refines a search to match documents whose specified field value is greater than the specified value.

Description

The gt() function refines a WixSearchBuilder to only match documents where the value of the specified field is greater than the specified value.

gt() 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 properties can be compared:

  • Number: Compares numerically.
  • Date: Compares JavaScript Date objects.
  • String: Compares lexicographically, so "text" is greater than "Text".

If other filters were previously used in the same WixSearchBuilder instance, gt() is applied using an and condition with previously set filters.

Syntax

function gt(field: string, value: string | number | Date): WixSearchBuilder

gt 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 WixSearchBuilder object representing the refined search.

Return Type:

Was this helpful?

Add a greater than filter to a search

Copy Code
1let newSearch = search
2 .documentType("Forum/Content")
3 .gt("likeCount", 10);
Create a search, add a greater than filter, and run it

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5wixSearch.search()
6 .documentType("Forum/Content")
7 .gt("totalComments", 5)
8 .find()
9 .then( (results) => {
10 if(results.documents.length > 0) {
11 let documents = results.documents;
12 } else {
13 console.log("No matching results");
14 }
15 })
16 .catch( (error) => {
17 console.log(error);
18 });