Filters and Facets
- **Using Filters, you can restrict your search by URL/domain, meta fields, file type/content type, language, size range, date range, and more.
- Filtered search can be applied to a subset of a collection or a group of collections, and filters can also be created directly from queries.
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 limit search results using URL, domain, or subpaths.
If you want results only from a specific domain like www.bbc.com, you can write:
Example:
url:"en.wikipedia.org"
To filter results using subpaths, you can do:
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 these filters:
Example:
language:en
for filtering results in English
language:ja
for filtering results in Japanese
You can check more language codes on this page:
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 these filters:
contenttype:pdf
for filtering pdf files
contenttype:word
for filtering word files
For all supported file formats, visit:
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 the indexed meta tags, you can filter results using meta tag parameters.
For example, if the meta tag is category, you can filter like this:
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
The NOT filter is used to exclude a specific term or field.
For example, if you don’t want results from the collection test, you can use:
&filter=NOT(colname:test)
You can also use NOT for file types or 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
You can combine multiple filters using boolean operators, and here are some examples.
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")](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:floodAND(title:2018)AND(keywords:flood))
Facet Filters
You can add facet filters in the URL by using a few parameters.
Prerequisite:
Add the field in ../searchblox/webapps/ROOT/WEB-INF/mapping.json before using facet filters.
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: turn on the filter, choose the field, set the size range, and then apply the 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: enable the filter, choose the field, set the range, and then apply the 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:Use 4 filter parameters:
- enable facet
- select the field
- set the range
- apply the 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 28 days ago
