Integrating Search
Filtering Content
To learn more about the difference between filters and facets, read our blog post.
Filters allow users to filter search results based on a condition.
You can use filters in a few ways:
- Static filters which allow end-users to filter content after entering a search query.
- Dynamic filters (also referred to as facets), which are generated based on the values of the search result set.
- Filter results using filter expressions. In this case, the end-users will always see the filtered results.
1. Static filters
Static filters can be applied when a user interacts with a UI component (e.g. a tab-filter, radio buttons, or checkboxes). You can set up tab filters easily when you generate a Search Interface in the console.
As an example use case, you can provide users with preset tab filters to filter different domains (blog, news, docs). Another example use case is to create filters to allow users to based on rating (1-5 stars).
2. Dynamic filters
Dynamic filters (also referred to as facets) are generated based on the values of the search result set. Learn more about dynamic filters (or facets).
You can also allow users to select multiple options in the search UI for both static and dynamic filters. A typical use-case of multiple fields is an Ecommerce store, where a user enters a search term, select multiple brands, and then filter price range. View the React SDK documentation to set up multi-select facets or filters.
3. Filter results using filter expressions
You can use filter expressions to filter content when making a search request.
As an example, if you are looking to filter out specific sections of a website, you can use filter to remove a specific section (e.g. you can filter out a blog section by using dir1!='blog'
). You can also test the filter expressions in our Preview section as well, refer to this documentation for more details.
If you are using our Website Search Integration, see more details down below.
Note: If you used a generated code from the Integrate section of your Console, you are also using Website Search Integration.
Usage
Filters are used to limit the results that are returned with a search. In a search interface filters are commonly seen as tabs, checkboxes, or sliders on the side.
To make filtering easier, our crawler extracts common fields when it crawls web pages (such as the first and second directories of URLs).
Aside from commonly used fields like title, description and og:image our crawler also extracts other fields which can be useful for filtering. Here are some examples that assume that the page URL is https://www.sajari.com/blog/year-in-review
:
url
The full page URL:https://www.sajari.com/blog/year-in-review
dir1
The first directory of the page URL: blogdir2
The second directory of the page URL: year-in-reviewdomain
The domain of the page URL:www.sajari.com
lang
The language of the page, extracted from the<html>
element (if present).
Using Operators
When querying a field, there are a few operators that can be used. Note, all
values must be enclosed in single quotation marks, i.e. "field boost must be
greater than 10" is written as boost>'10'
.
Operator | Description | Example |
---|---|---|
Equal To (= ) | Field is equal to a value (numeric or string) | dir1='blog' |
Not Equal To (!= ) | Field is not equal to a value (numeric or string) | dir1!='blog' |
Greater Than (> ) | Field is greater than a numeric value | boost>'10' |
Greater Than Or Equal To (>= ) | Field is greater than or equal to a numeric value | boost>='10' |
Less Than (< ) | Field is less than a given numeric value | boost<'50' |
Less Than Or Equal To (<= ) | Field is less than or equal to a given numeric value | boost<'50' |
Begins With (^ ) | Field begins with a string | dir1^'bl' |
Ends With ($ ) | Field ends with a string | dir1$'og' |
Contains (~ ) | Field contains a string | dir1~'blog' |
Does Not Contain (!~ ) | Field does not contain a string | dir1!~'blog' |
Combining expressions
It's also possible to build more complex filters by combining field filter
expressions with AND
/OR
operators, and brackets.
Operator | Description | Example |
---|---|---|
AND | Both expressions must match | dir1='blog' AND domain='www.sajari.com' |
OR | One expression must match | dir1='blog' OR domain='blog.sajari.com' |
For example, to match pages with language set to en
on www.sajari.com
or any
page within the en.sajari.com
domain:
(domain='www.sajari.com' AND lang='en') OR domain='en.sajari.com'