Let's imagine a free search box on a simple HTML prototype (we will play with it later). When we are writing our term, we write Hen
and pause a little for the interface to start suggesting something to us. The screen we see will be similar to what we see on the left side of the following screenshot:
On the left, we can see a simple prototype that gives an idea of how the results will be suggested to users when they write their terms for a search. To get the output shown in the previous screenshot, we perform the following steps:
Hen
, some suggestion is prompted, showing how many document results are available and also reporting the fields on which some matches are actually found. artist_entity
field, just to give an idea of what is behind the scenes.>> curl -X GET 'http://localhost:8983/solr/paintings/select?q=*:*&rows=0&facet=true&facet.field=artist_entity&facet.prefix=hen&wt=json'
/SolrStarterBook/solr-app/chp06/paintings
, restarting from the configuration used in Chapter 5, Extending Search.Here we retrieve a short list of suggestions for the field artist_entity
. As you can see, the response format gives us a suggested term, followed by the number of documents that currently match that request.
In this small example, we are not interested in obtaining results (rows=0
). Instead, we want to obtain a small list of items for a certain field (in the example, the field is artist_entity
) and get information about how many documents contain that term in particular. In order to do this, we have to activate the faceting capabilities
of Solr using facet=true
(it's possible to use facet=on
as for most Boolean parameters) and restrict the list of items to the ones that starts with a particular text, using facet.prefix=hen
. Note that we have to write the term in lowercase due to our previously adopted approach for analyzing the artist_entity
field, but we can change this if we want.
18.222.168.163