Search.../

gt( )

Creates a search filter for matching documents whose specified field value is greater than the specified value.

Description

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

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

Syntax

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

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 WixSearchFilter object.

Return Type:

WixSearchFilter
NAME
TYPE
DESCRIPTION
filterDefinition
Object

An object containing the filter definition.

Was this helpful?

Create a greater than search filter

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5const gtFilter = wixSearch
6 .filter()
7 .gt("viewCount", 50);
Create multiple search filters and add them to a search

This example demonstrates how to create multiple search filters and combine them to search for forum posts with more than 200 views that were posted either in the month of January or April of 2020.

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5const filterBuilder = wixSearch.filter();
6
7const gtJanFilter = filterBuilder.gt("lastActivityDate", "2020-01-01T00:00:00.000Z");
8const ltFebFilter = filterBuilder.lt("lastActivityDate", "2020-02-01T00:00:00.000Z");
9
10const gtAprilFilter = filterBuilder.gt("lastActivityDate", "2020-04-01T00:00:00.000Z");
11const ltMayFilter = filterBuilder.lt("lastActivityDate", "2020-05-01T00:00:00.000Z");
12
13const januaryFilter = filterBuilder.and(gtJanFilter, ltFebFilter);
14const aprilFilter = filterBuilder.and(gtAprilFilter, ltMayFilter);
15
16const dateFilter = filterBuilder.or(januaryFilter, aprilFilter)
17
18const viewFilter = filterBuilder.gt("viewCount", 200)
19
20wixSearch.search(phrase)
21 .documentType("Forum/Content")
22 .and(dateFilter, viewFilter)
23 .find()
24 .then( (results) => {
25 if(results.documents.length > 0) {
26 let documents = results.documents;
27 } else {
28 console.log("No matching results");
29 }
30 })
31 .catch( (error) => {
32 console.log(error);
33 });
Create filters and add them to a search

This example demonstrates how to create filters that search for forum posts in a specific forum category, that contain the hashtags "summer" and "fun", and that were posted/updated on or after January 1, 2020. The filters are joined and chained to a search using an and() filter.

Copy Code
1import wixSearch from 'wix-search';
2
3// ...
4
5const filterBuilder = wixSearch.filter();
6
7const gtFilter = filterBuilder.gt("lastActivityDate", "2020-01-01T00:00:00.000Z");
8
9const hasAllFilter = filterBuilder.hasAll("hashTags", ["summer", "fun"]);
10
11const eqFilter = filterBuilder.eq(categoryId, "5df7504fa8a9b30017fc1053");
12
13wixSearch.search(phrase)
14 .documentType("Forum/Content")
15 .and(gtFilter, hasAllFilter, eqFilter)
16 .find()
17 .then( (results) => {
18 if(results.documents.length > 0) {
19 let documents = results.documents;
20 } else {
21 console.log("No matching results");
22 }
23 })
24 .catch( (error) => {
25 console.log(error);
26 });