Filter
This topic lists the various filter object definitions included in Sitecore Search JavaScript SDK for React.
A filter object that contains the attribute name, the value, and how to compare the two.
FilterEqual
Creates a filter object that checks if an item's attribute exactly matches the value provided.
|
Property |
Type |
Description |
|---|---|---|
|
|
string |
Required. Name of attribute. |
|
|
any |
Required. The value to compare against. |
query.getRequest().setSearchFilter( new FilterEqual( 'category', 'bags') );query.getRequest().setSearchFilter( new FilterEqual( 'type', 'blog') );FilterLessThan
Creates a filter object that checks if an item's attribute is less than the value provided.
|
Property |
Type |
Description |
|---|---|---|
|
|
string |
Required. Name of attribute. |
|
|
any |
Required. The value to compare against. |
query.getRequest().setSearchFilter( new FilterLessThan( 'price', '10') );FilterGreaterThan
Creates a filter object that checks if an item's attribute is greater than the value provided.
|
Property |
Type |
Description |
|---|---|---|
|
|
string |
Required. Name of attribute. |
|
|
any |
Required. The value to compare against. |
query.getRequest().setSearchFilter( new FilterGreaterThan( 'unitsAvailable', '20') );FilterLessOrEqualThan
Creates a filter object that checks if an item's attribute is less than or exactly matches the value provided.
|
Property |
Type |
Description |
|---|---|---|
|
|
string |
Required. Name of attribute. |
|
|
any |
Required. The value to compare against. |
query.getRequest().setSearchFilter( new FilterLessOrEqualThan( 'price', '4') );FilterGreaterOrEqualThan
Creates a filter object that checks if an item's attribute is greater than or exactly matches the value provided.
|
Property |
Type |
Description |
|---|---|---|
|
|
string |
Required. Name of attribute. |
|
|
any |
Required. The value to compare against. |
query.getRequest().setSearchFilter( new FilterGreaterOrEqualThan( 'unitsAvailable', '10') );FilterGeo
Creates a filter object that checks if an item's attribute exactly matches the value provided.
|
Property |
Type |
Description |
|---|---|---|
|
|
string |
Required. Name of attribute. |
|
|
string |
Required. The value to compare against must include a number and the unit. See the example request below for reference. Units accepted include "in", "ft", "yd", "mi", "nmi", "km", "m", "cm", and "mm". |
|
|
float |
Latitude of location in decimal degrees (DD) format. Don't use spaces. For example, 23.928666 |
|
|
float |
Longitude of location in decimal degrees (DD) format. Don't use spaces. For example, -50.928666 |
query.getRequest().setSearchFilter(new FilterGeo('location', '2000km', { lat: -8.1319026, lon: -34.9022836 }));FilterAnyOf
Creates a filter object that checks if an item's attribute exactly matches any of the values in the array.
|
Property |
Type |
Description |
|---|---|---|
|
|
string |
Required. Name of attribute. |
|
|
array |
Required. The array of values to compare against. |
query.getRequest().setSearchFilter( new FilterAnyOf('type', ['blog', 'webinar'] ) );FilterAnd
Creates a filter object that includes an item when it matches all the filter objects in the provided array.
|
Property |
Type |
Description |
|---|---|---|
|
|
array |
Required. The array of filter objects to compare against. |
query.getRequest().setSearchFilter( new FilterAnd ( [ new FilterEqual( 'type', 'blog'), new FilterEqual( 'category', 'movies') ] ) );FilterOr
Creates a filter object that includes an item when it matches any of the filter objects in the provided array.
|
Property |
Type |
Description |
|---|---|---|
|
|
array |
Required. The array of filter objects to compare against. |
query.getRequest().setSearchFilter( new FilterOr ( [ new FilterEqual( 'type', 'blog'), new FilterEqual( 'category', 'ezine') ] ) );FilterNot
Creates a filter object that excludes an item if its attribute matches the filter objects in the provided array.
|
Property |
Type |
Description |
|---|---|---|
|
|
array |
Required. The array of filter objects to compare against. |
query.getRequest().setSearchFilter( new FilterNot ( [ new FilterEqual( 'type', 'blog'), new FilterEqual( 'category', 'ezine') ] ) );FilterGeoWithin
Creates a filter object that excludes items outside the polygon created by an array of coordinates, known as a point object.
|
Property |
Type |
Description |
|---|---|---|
|
|
string |
Name or reference of location. |
|
|
Array<Point> |
Required. Array of |
The point object contains latitude and longitude coordinates. See the example request below for reference.
|
Property |
Type |
Description |
|---|---|---|
|
|
float |
Required. Latitude of location in decimal degrees (DD) format. Don't use spaces. For example: -28.281932 |
|
|
float |
Required. Longitude of location in decimal degrees (DD) format. Don't use spaces. For example: -50.928666 |
const coordinates = [
{
lat: -28.281932,
lon: -55.573635,
},
{
lat: -31.254713,
lon: -50.928666,
},
{ lat: -16.181724,
lon: -47.217881 },
];
query.getRequest().setSearchFilter(new FilterGeoWithin('location', coordinates));