Faceted Navigation & Filtering

Solr API

A facet counts how many results have each value of a field: English (834), German (245). Clicking a value adds a filter, and the counts follow.

01 · Ask for counts

facet=true
facet.field=meta_detected_language
facet.field=meta_domain
facet.mincount=1
facet.limit=20

facet.mincount=1 hides values with no results; facet.limit caps the number of values (100 when you do not send it). How to read the answer: the JSON response.

02 · Filter on a value

fq={!term f=meta_detected_language}de

The term parser takes the value exactly as it is, spaces and punctuation included, so a value read from a facet goes back into the filter with no escaping. With several fq, a result must match them all.

03 · Keep the other values visible

fq={!tag=lang}{!term f=meta_detected_language}de
facet.field={!ex=lang}meta_detected_language

The tag names the filter and ex tells that facet to count as if its own filter were not there. German stays selected, and the other languages keep their counts so the visitor can switch. The hosted search page does this for every facet.

04 · Ranges

facet.range=creation_date
facet.range.start=NOW/MONTH-11MONTHS
facet.range.end=NOW
facet.range.gap=+1MONTH

facet.range=price_f
facet.range.start=0
facet.range.end=500
facet.range.gap=50

The counts come back in facet_counts.facet_ranges. Filter on a range with fq=price_f:[50 TO 100].

05 · Which fields can be facets

String, number and date fields: meta_detected_language, meta_og_locale, meta_domain, content_type, category, currency_s, price_f, creation_date, and any *_s, *_ss, *_i, *_f or *_dt field your documents carry. Text fields such as title cannot be facets. The fields of your own index, by API: get_facetable_fields.

06 · Without code

The hosted search page has a facet sidebar you set up in the Control Panel: facet filters, Facet Filter Mapping and the five widgets.