Apache Solr v9 Range Faceting Tutorial
This tutorial does not cover all Range Facet options. Refer to the document link above for full details.
This tutorial will cover some of the facet options along with visual examples to help solidify your understanding.
This is the subset of parameters that are explained in this tutorial.
This tutorial is based on code that uses SolrJ and the RangeFacetMap. Here is an example of code.
RangeFacetMap rangeFacetMap = new RangeFacetMap("BirthYears",
1910,
1950,
3);
//Note: If additional parameters are needed, put them directly into the facet map
//by key according to documentation.
// https://solr.apache.org/guide/solr/latest/query-guide/faceting.html
//
// Example: rangeFacetMap.put("hardened",true)
// Example: rangeFacetMap.put("include",Make.listOf("upper"))
// Example: rangeFacetMap.put("other", "after")
Facet Data
The example data is a birth year field and the count of records that have that birth year.
Gap Size 1
RangeFacetMap rangeFacetMap = new RangeFacetMap("BirthYears",
1900,
1907,
1);
Each bucket is represented by a unique color.
Lower
All gap based ranges include their lower bound.
Start = 1900, End = 1907, Gap = 1, include = “lower”
Upper
All gap based ranges include their upper bound.
Start = 1900, End = 1907, Gap = 1, include = “upper”
Edge
The first and last gap ranges include their edge bounds (i.e., lower for the first one, upper for the last one)
even if the corresponding upper/lower option is not specified.
Start = 1900, End = 1907, Gap = 1, include = “edge”
UPPER and LOWER
Start = 1900, End = 1907, Gap = 1, include = “lower”, “upper”
Gap Size 2
RangeFacetMap rangeFacetMap = new RangeFacetMap("BirthYears",
1900,
1907,
2);
Each bucket is represented by a unique color.
Lower
All gap based ranges include their lower bound.
Start = 1900, End = 1907, Gap = 2, include = “lower”
Upper
All gap based ranges include their upper bound.
Start = 1900, End = 1907, Gap = 2, include = “upper”
Edge
The first and last gap ranges include their edge bounds (i.e., lower for the first one, upper for the last one)
even if the corresponding upper/lower option is not specified.
Start = 1900, End = 1907, Gap = 2, include = “edge”
UPPER and LOWER
Start = 1900, End = 1907, Gap = 2, include = “lower”, “upper”
Gap Size 3
RangeFacetMap rangeFacetMap = new RangeFacetMap("BirthYears",
1900,
1907,
3);
Each bucket is represented by a unique color.
Lower
All gap based ranges include their lower bound.
Start = 1900, End = 1907, Gap = 3, include = “lower”
Upper
All gap based ranges include their upper bound.
Start = 1900, End = 1907, Gap = 3, include = “upper”
Edge
The first and last gap ranges include their edge bounds (i.e., lower for the first one, upper for the last one)
even if the corresponding upper/lower option is not specified.
Start = 1900, End = 1907, Gap = 3, include = “edge”
Gap Size 4
RangeFacetMap rangeFacetMap = new RangeFacetMap("BirthYears",
1900,
1907,
4);
Each bucket is represented by a unique color.
Lower
All gap based ranges include their lower bound.
Start = 1900, End = 1907, Gap = 4, include = “lower”
Upper
All gap based ranges include their upper bound.
Start = 1900, End = 1907, Gap = 4, include = “upper”
Edge
The first and last gap ranges include their edge bounds (i.e., lower for the first one, upper for the last one)
even if the corresponding upper/lower option is not specified.
Start = 1900, End = 1907, Gap = 4, include = “edge”
Gap Size 5
RangeFacetMap rangeFacetMap = new RangeFacetMap("BirthYears",
1900,
1907,
5);
Each bucket is represented by a unique color.
Lower
All gap based ranges include their lower bound.
Start = 1900, End = 1907, Gap = 5, include = “lower”
Upper
All gap based ranges include their upper bound.
Start = 1900, End = 1907, Gap = 5, include = “upper”
Edge
The first and last gap ranges include their edge bounds (i.e., lower for the first one, upper for the last one)
even if the corresponding upper/lower option is not specified.
Start = 1900, End = 1907, Gap = 5, include = “edge”