The Filter objects
Sitecore Search offers various ways of filtering results. You can use many properties to define and narrow results in a filter object. Filters are added to the WidgetRequest. There are three types of filter: comparative filters, logic operator filters, and list filters as listed in the following sections. Each section lists filter objects that can be added to the request.
Comparative filters
Every search query associates a widget with an entity. Use this filter to compare an attribute of the entity with a value. To instantiate one of these filters, provide the attribute's name and compared value.
const filterLessThan = new FilterLessThan ( "numOfWords", 1000 );
const filterLessOrEqualThan = new FilterLessOrEqualThan ( "durationInMinutes", 70 );
const filterEqual = new FilterEqual ( "title", "Introduction" );
const filterGreaterThan = new FilterGreaterThan ( "numOfWords", 400 );
const filterGreaterOrEqualThan = new FilterGreaterOrEqualThan ( "numOfWords", 400);
const widgetRequest = new WidgetRequest("rfkid_7");
const filterGreaterThan = new FilterGreaterThan ( "durationInMinutes", 2 );
widgetRequest.setSearchFilter ( Filter )Logic operator filter
Use this filter to provide multiple filters as options based on some logic. To instantiate one of these filters, provide an array of filters, as shown in the following code block.
const filterLessOrEqualThan = new FilterLessOrEqualThan ( "durationInMinutes", 70 );
const filterEqual = new FilterEqual ( "title", "Introduction" );
const filterOr = new FilterOr ( [ new FilterLessThan ( "numOfWords", 400 ), new FilterGreaterThan ( "numOfWords", 1000 ) ] );
const filterAnd = new FilterAnd ( [ filterEqual, new FilterLessThan ( "numOfWords", 1000 ) ] );
const filterNot = new FilterNot ( [ filterEqual, filterLessOrEqualThan ]);List filter
Use these filters to use multiple values for an attribute. To instantiate one of these filters, provide the attribute name and an array of values, as shown in the following code block.
const filterAllOf = new FilterAllOf ( "type", [ "video", "film", "audio" ] );
const filterAnyOf = new FilterAnyOf ( "type", [ "video", "film", "audio" ] );Filter methods
The following code block lists the various methods related to filtering and accessible through the WidgetRequest object.
/** search.filter */]
getSearchFilter(): Filter;
setSearchFilter(value: Filter): IWidgetItem;
resetSearchFilter(): IWidgetItem;