1. Query

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.

PropertyTypeDescription
attributestringRequired.

Name of attribute.
valueanyRequired.

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.

PropertyTypeDescription
attributestringRequired.

Name of attribute.
valueanyRequired.

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.

PropertyTypeDescription
attributestringRequired.

Name of attribute.
valueanyRequired.

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.

PropertyTypeDescription
attributestringRequired.

Name of attribute.
valueanyRequired.

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.

PropertyTypeDescription
attributestringRequired.

Name of attribute.
valueanyRequired.

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.

PropertyTypeDescription
attributestringRequired.

Name of attribute.
radiusstringRequired.

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".
latfloatLatitude of location in decimal degrees (DD) format. Don't use spaces. For example, 23.928666
lonfloatLongitude 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.

PropertyTypeDescription
attributestringRequired.

Name of attribute.
arrayarrayRequired.

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.

PropertyTypeDescription
arrayarrayRequired.

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.

PropertyTypeDescription
arrayarrayRequired.

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.

PropertyTypeDescription
arrayarrayRequired.

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.

PropertyTypeDescription
namestringName or reference of location.
arrayArrayRequired.

Array of point objects

The point object contains latitude and longitude coordinates. See the example request below for reference.

PropertyTypeDescription
latfloatRequired.

Latitude of location in decimal degrees (DD) format. Don't use spaces. For example: -28.281932
lonfloatRequired.

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));
If you have suggestions for improving this article, let us know!