Facet navigation
We've seen previously how Solr provides a facet, by using which we can put indexed data into groups depending on the fields. Let's see how we can improve user experience while selecting the type of music by grouping music into genres.
We can use facet=true
to enable faceting of fields, and then use facet.field=genre
to return the number of songs that are in each category. The search query will return only the facet data and will look like this:
http://localhost:8983/solr/musicStore/select?q=*%3A*&start=0&rows=0&wt=json&indent=true&facet=true&facet.field=genre
As we're interested in the facet data only, we've specified rows=0
. This URL will return us the following data:
{ "responseHeader":{ }, "response":{ }, "facet_counts":{ "facet_queries":{ }, "facet_fields":{ "genre":[ "Pop", 3, "Dance/Electronic...