1. Overview

Solr provide facility to group or cluster search result into categories that let users drill into search results by any value in any field. Solr faceting is used in many applications to give an overall idea about how the data resides in the index.

In the first part of Solr faceting solr field value faceting, If you haven’t read it please refer first blog first for better understanding of solr faceting. we have discussed field value faceting, In this article, we will discuss the seconds part of Solr faceting i.e Solr Range Faceting.

Solr provide Range faceting to get range wise results.We can use range faceting on any date or any numeric fields that support range queries.

2. Range Faceting parameters

Let’s discuss various parameters with detail explanation.

2.1 facet.range

facet.range parameter defined the field which we want to range facet.We can give multiple fields by giving multiple times in query as below.

facet.range=doc_attachment_conut
  &facet.range=doc_total_page
  &facet.range=doc_file_size

2.2 facet.range.start

The facet.range.start parameter used to specified lower bound of a range. We can specify lower bounds for multiple fields using field specific syntax(f.<field_name>.facet.range.start).

facet.range=doc_attachment_conut
  &facet.range=doc_total_page
  &facet.range=doc_file_size
  &f.doc_attachment_count.facet.range.start=1
  &f.doc_total_page.facet.range.start=5
  &f.doc_doc_file_size.facet.range.start=100

2.3 facet.range.end

The facet.range.end parameter used to specify upper bound of a range. We can specify upper bounds for multiple fields using field specific syntax(f.<field_name>.facet.range.end).

facet.range=doc_attachment_conut
  &facet.range=doc_total_page
  &facet.range=doc_file_size
  &f.doc_attachment_count.facet.range.start=1
  &f.doc_total_page.facet.range.start=5
  &f.doc_doc_file_size.facet.range.start=100
  &f.doc_attachment_count.facet.range.end=10
  &f.doc_total_page.facet.range.end=50
  &f.doc_doc_file_size.facet.range.end=999

2.4 facet.range.gap

The facet.range.gap parameter used to specify span for each range. By this parameter we can add drill down charts in our application for date type fields by narrowing gap like year, month , day ,hour etc…

facet.range=doc_attachment_conut
  &facet.range=last_modified_date
  &f.doc_attachment_count.facet.range.start=1
  &f.doc_attachment_count.facet.range.end=10
  &f.doc_attachment_count.facet.range.gap=2
  &f.last_modified_date.facet.range.start=1990-01-01T00:00:00Z
  &f.last_modified_date.facet.range.end=2018-01-01T23:59:59Z
  &f.last_modified_date.facet.range.gap=+1YEAR

3. Date Range Faceting Example

In below example we have indexed some dummy data to check date range faceting.Here we kept date one year as range gap.

&facet=true
  &facet.range=last_modified_date
  &f.last_modified_date.facet.range.start=2000-01-01T00:00:00Z
  &f.last_modified_date.facet.range.end=2018-01-01T23:59:59Z
  &f.last_modified_date.facet.range.gap=%2B1YEAR

By executing above query we will get the output as below.

solr date range faceting

 

In Real life use cases, users drill down to specific documents/datasets by changing gap value from year, month, day etc.. which give an in-depth idea about data.

solr date range faceting 2

 

4. Numeric Range Faceting Example

As date range faceting solr will also support range faceting on any numeric fields.In our example we will use int field doc_attachment_count.

&facet=true
  &facet.range=doc_attachment_conut
  &f.doc_attachment_conut.facet.range.start=1
  &f.doc_attachment_conut.facet.range.end=18
  &f.doc_attachment_conut.facet.range.gap=2

By executing above query solr give the result as below.

Solr date range faceting 3

5. Conclusion

In this article, Basic query syntax of solr numeric range faceting and date range faceting. we have discussed solr range faceting with important range parameters and some of the basic examples.

6. References

Refer solr field value faceting and Solr Reference Guide for more details.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *