Skip to content

Instantly share code, notes, and snippets.

@agustinhaller
Created July 7, 2014 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agustinhaller/0f2bfe08800f3c46f9a7 to your computer and use it in GitHub Desktop.
Save agustinhaller/0f2bfe08800f3c46f9a7 to your computer and use it in GitHub Desktop.
Faceted Search
Faceted search takes the documents matched by a query and generates counts for various properties or categories. Links are usually provided that allows users to "drill down" or refine their search results based on the returned categories.
The following example searches for all documents (*:*) and requests counts by the category field cat.
...&q=*:*&facet=true&facet.field=cat
Notice that although only the first 10 documents are returned in the results list, the facet counts generated are for the complete set of documents that match the query.
We can facet multiple ways at the same time. The following example adds a facet on the boolean inStock field:
...&q=*:*&facet=true&facet.field=cat&facet.field=inStock
Solr can also generate counts for arbitrary queries. The following example queries for ipod and shows prices below and above 100 by using range queries on the price field.
...&q=ipod&facet=true&facet.query=price:[0 TO 100]&facet.query=price:[100 TO *]
Solr can even facet by numeric ranges (including dates). This example requests counts for the manufacture date (manufacturedate_dt field) for each year between 2004 and 2010.
...&q=*:*&facet=true&facet.range=manufacturedate_dt&facet.range.start=2004-01-01T00:00:00Z&facet.range.end=2010-01-01T00:00:00Z&facet.range.gap=+1YEAR
More information on faceted search may be found on the faceting overview and faceting parameters pages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment