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.
http://developer.searchblox.com/docs/search-parameters
http://developer.searchblox.com/docs/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
[http://localhost:8080/searchblox/servlet/SearchServlet?query=* AND url:"en.wikipedia.org"](http://localhost:8080/searchblox/servlet/SearchServlet?query= AND url:"en.wikipedia.org")
or
[http://localhost:8080/searchblox/servlet/SearchServlet?query=
&filter=url:"en.wikipedia.org"](http://localhost:8080/searchblox/servlet/SearchServlet?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.
http://developer.searchblox.com/docs/search-parameters

Example URL
[http://localhost:8080/searchblox/servlet/SearchServlet?query=*AND language:en](http://localhost:8080/searchblox/servlet/SearchServlet?query=AND language:en)
or
[http://localhost:8080/searchblox/servlet/SearchServlet?query=
&filter=language:ja](http://localhost:8080/searchblox/servlet/SearchServlet?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
http://developer.searchblox.com/docs/supported-file-formats.

Example URL
[http://localhost:8080/searchblox/servlet/SearchServlet?query=* AND contenttype:pdf](http://localhost:8080/searchblox/servlet/SearchServlet?query= AND contenttype:pdf)
or
[http://localhost:8080/searchblox/servlet/SearchServlet?query=
&filter=contenttype:word](http://localhost:8080/searchblox/servlet/SearchServlet?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
[http://localhost:8080/searchblox/servlet/SearchServlet?query=* AND category:fruit](http://localhost:8080/searchblox/servlet/SearchServlet?query= AND category:fruit)
or
[http://localhost:8080/searchblox/servlet/SearchServlet?query=
&filter=category:fruit](http://localhost:8080/searchblox/servlet/SearchServlet?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
[http://localhost:8080/searchblox/servlet/SearchServlet?query=*&filter=NOT(contenttype:word)](http://localhost:8080/searchblox/servlet/SearchServlet?query=&filter=NOT(contenttype:word)
[http://localhost:8080/searchblox/servlet/SearchServlet?query=
&filter=NOT(category:fruit)](http://localhost:8080/searchblox/servlet/SearchServlet?query=*&filter=NOT(category:fruit)

Multiple filters

Multiple filters can be used using boolean operators, please find few examples here:
Multiple titles
[http://localhost:8080/searchblox/servlet/SearchServlet?facet=true&query=*&filter=title:(bbc%20OR%20Africa)](http://localhost:8080/searchblox/servlet/SearchServlet?facet=true&query=&filter=title:(bbc%20OR%20Africa)
[http://localhost:8080/searchblox/servlet/SearchServlet?facet=true&query=
&filter=title:(bbc%20AND%20Africa)](http://localhost:8080/searchblox/servlet/SearchServlet?facet=true&query=&filter=title:(bbc%20AND%20Africa)
Multiple urls
[http://localhost:8080/searchblox/servlet/SearchServlet?facet=true&query=
&filter=url:("www.cnn.com"OR"www.bbc.com")](http://localhost:8080/searchblox/servlet/SearchServlet?facet=true&query=*&filter=url:("www.cnn.com"OR"www.bbc.com")

Multiple fields
http://localhost:8080/searchblox/servlet/SearchServlet?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/searchblox/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 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 ../searchblox/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: http://localhost:8080/searchblox/servlet/SearchServlet?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 ../searchblox/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: [http://localhost:8080/searchblox/servlet/SearchServlet?query=time&facet=true&facet.field=numfield&f.numfield.range=[*TO500]& f.numfield.filter=[100TO200]](http://localhost:8080/searchblox/servlet/SearchServlet?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 ../searchblox/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: [http://localhost:8080/searchblox/servlet/SearchServlet?query=time&facet=true&facet.field=datefield&f.datefield.range=[*TO2019-06-20]& f.numfield.filter=[2012-06-20TO2016-06-20]](http://localhost:8080/searchblox/servlet/SearchServlet?query=time&facet=true&facet.field=datefield&f.datefield.range=[*TO2019-06-20]& f.numfield.filter=[2012-06-20TO2016-06-20])