Filters and Facets
Using Filters, you can restrict search to URL or domain, meta fields, file type or content type, language, size ranges, intervals based on date, etc. Filtered search can be implemented for a subset of a collection, or on a group of collections.
Filters can be directly implemented from queries. The different filter options are listed here.
Filters can be given as URL params or facet filters using UI. Follow the following links for more information.
Search Parameters
Faceted Search
Filters for URL
You can use this filter to restrict results based on the URL, domain or subpaths.
If you want results with the domain name www.bbc.com, the query can be given as
Example:
url:"en.wikipedia.org"
To filter the results based on domain, you can also search subpaths:
Example:
url:"/travel"
If you dont want results from a particular domain or subpath, use the prefix - in the beginning of the field
Example:
-url:"en.wikipedia.org"
or
-url:"/travel"
Example URLs
[https://localhost:8443/rest/v2/api/search?public=true&query=* AND url:"en.wikipedia.org"](https://localhost:8443/rest/v2/api/search?public=true&query= AND url:"en.wikipedia.org")
or
[https://localhost:8443/rest/v2/api/search?public=true&query=&filter=url:"en.wikipedia.org"](https://localhost:8443/rest/v2/api/search?public=true&query=*&filter=url:"en.wikipedia.org")
Filters for Language
Filtering can be done based on language using the following filters:
Example:
language:en
for filtering results in English
language:ja
for filtering results in Japanese
Please refer to this page for different language codes.
https://developer.searchblox.com/docs/search-parameters
Example URL
[https://localhost:8443/rest/v2/api/search?public=true&query=*AND language:en](https://localhost:8443/rest/v2/api/search?public=true&query=AND language:en)
or
[https://localhost:8443/rest/v2/api/search?public=true&query=&filter=language:ja](https://localhost:8443/rest/v2/api/search?public=true&query=*&filter=language:ja)
Filters for File Types
File types can be filtered using the following filters:
contenttype:pdf
for filtering pdf files
contenttype:word
for filtering word files
For the file formats supported, refer to
https://developer.searchblox.com/docs/supported-file-formats.
Example URL
[https://localhost:8443/rest/v2/api/search?public=true&query=* AND contenttype:pdf](https://localhost:8443/rest/v2/api/search?public=true&query= AND contenttype:pdf)
or
[https://localhost:8443/rest/v2/api/search?public=true&query=&filter=contenttype:word](https://localhost:8443/rest/v2/api/search?public=true&query=*&filter=contenttype:word)
Filters for Meta Tags
Based on meta tags indexed, filtering can be done using the following filter parameters.
For example, if the meta tag is category, you can use filter:
category:fruit
Example URL
[https://localhost:8443/rest/v2/api/search?public=true&query=* AND category:fruit](https://localhost:8443/rest/v2/api/search?public=true&query= AND category:fruit)
or
[https://localhost:8443/rest/v2/api/search?public=true&query=&filter=category:fruit](https://localhost:8443/rest/v2/api/search?public=true&query=*&filter=category:fruit)
Filters can also be given for title, keywords, description and any other fields indexed in collections in SearchBlox.
NOT filter
NOT filter can be used to avoid certain term or field. For example if you do not want the collection test you can give this parameter as shown
&filter=NOT(colname:test)
Similarly this NOT filter can be used for SearchBlox as well as meta fields
[https://localhost:8443/rest/v2/api/search?public=true&query=*&filter=NOT(contenttype:word)](https://localhost:8443/rest/v2/api/search?public=true&query=&filter=NOT(contenttype:word)
[https://localhost:8443/rest/v2/api/search?public=true&query=&filter=NOT(category:fruit)](https://localhost:8443/rest/v2/api/search?public=true&query=*&filter=NOT(category:fruit)
Multiple filters
Multiple filters can be used using boolean operators, please find few examples here:
Multiple titles
[https://localhost:8443/rest/v2/api/search?public=true&facet=true&query=*&filter=title:(bbc%20OR%20Africa)](https://localhost:8443/rest/v2/api/search?public=true&facet=true&query=&filter=title:(bbc%20OR%20Africa)
[https://localhost:8443/rest/v2/api/search?public=true&facet=true&query=&filter=title:(bbc%20AND%20Africa)](https://localhost:8443/rest/v2/api/search?public=true&facet=true&query=&filter=title:(bbc%20AND%20Africa)
Multiple urls
[https://localhost:8443/rest/v2/api/search?public=true&facet=true&query=&filter=url:("www.cnn.com"OR"www.bbc.com")](https://localhost:8443/rest/v2/api/search?public=true&facet=true&query=*&filter=url:("www.cnn.com"OR"www.bbc.com")
Multiple fields
https://localhost:8443/rest/v2/api/search?public=true&facet=true&query=*&filter=url:("www.cnn.com"OR"www.bbc.com")AND(title:2018)AND(keywords:flood)
Facet Filters
One can provide facet filters in url using a set of parameters
Prerequisite:
It is required to add the field in ../searchblox/webapps/ROOT/WEB-INF/mapping.json, only then it would be possible to use facet filters for the field.
Step 1:
Initially, it is required to enable the facet parameter by giving the value as true. This can be given once in the url if there are multiple facets
facet=true
Step 2:
Declare the name of the field as shown
facet.field=testfield
Step 3:
If the field is a text or string one can provide size to limit the number of filter results
f.textfield.size=20
If the field is a date or numerical value then you need to provide a range
Number:
f.numfield.range=[*TO500]
Date:
f.datefield.range=[*TO2019-06-20]
Step 4:
Then the filter can be provided as shown:
Text:
f.textfield.filter=test
Number:
f.numfield.filter=[100TO200]
Date:
f.datefield.filter=[2012-06-20TO2016-06-20]
Sample facet filters:
Text:
facet=true&facet.field=textfield&f.textfield.size=25&f.textfield.filter=travel
Number:
facet=true&facet.field=numfield&f.numfield.range=[*TO500]& f.numfield.filter=[100TO200]
Date:
facet=true&facet.field=datefield&f.datefield.range=[*TO2019-06-20]& f.numfield.filter=[2012-06-20TO2016-06-20]
Configuring String Facet Filters
Step 1: Add the facet field in ../ROOT/WEB-INF/mapping.json
"textfield": {
"type": "text",
"store": true,
"fielddata": true,
"analyzer": "comma_analyzer"
},
Step 2: Clear and reindex
Step 3:Give 4 filter parameters that is, enable filter, declare the field, specify size and then filter
facet=true&facet.field=textfield&f.textfield.size=25&f.textfield.filter=travel
example: https://localhost:8443/rest/v2/api/search?public=true&query=time&facet=true&facet.field=textfield&f.textfield.size=25&f.textfield.filter=travel
Configuring Numerical Facet Filters
Step 1: Add the facet field in ../ROOT/WEB-INF/mapping.json
"numfield": {
"type": "double",
"store": true,
"index": false
},
Step 2: Clear and reindex
Step 3:Give 4 filter parameters that is, enable filter, declare the field, specify range and then filter
facet=true&facet.field=numfield&f.numfield.range=[*TO500]& f.numfield.filter=[100TO200]
example: [https://localhost:8443/rest/v2/api/search?public=true&query=time&facet=true&facet.field=numfield&f.numfield.range=[*TO500]& f.numfield.filter=[100TO200]](https://localhost:8443/rest/v2/api/search?public=true&query=time&facet=true&facet.field=numfield&f.numfield.range=[*TO500]& f.numfield.filter=[100TO200])
Configuring Date Facet Filters
Step 1: Add the facet field in ../ROOT/WEB-INF/mapping.json
"datefield": {
"type": "date",
"store": "yes",
"include_in_all": "false"
},
Step 2: Clear and reindex
Step 3:Give 4 filter parameters that is, enable filter, declare the field, specify range and then filter
facet=true&facet.field=datefield&f.datefield.range=[*TO2019-06-20]& f.numfield.filter=[2012-06-20TO2016-06-20]
example: [https://localhost:8443/rest/v2/api/search?public=true&query=time&facet=true&facet.field=datefield&f.datefield.range=[*TO2019-06-20]& f.numfield.filter=[2012-06-20TO2016-06-20]](https://localhost:8443/rest/v2/api/search?public=true&query=time&facet=true&facet.field=datefield&f.datefield.range=[*TO2019-06-20]& f.numfield.filter=[2012-06-20TO2016-06-20])
Updated about 3 years ago