Time for action – prototyping an auto-suggester with facets

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:

Time for action – prototyping an auto-suggester with facets

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:

  1. When the user writes the term Hen, some suggestion is prompted, showing how many document results are available and also reporting the fields on which some matches are actually found.
  2. On the right, I put an example that includes only the raw suggestion results for the artist_entity field, just to give an idea of what is behind the scenes.
  3. We do not have a prototype yet, but we can easily simulate the output shown on the right by the request:
    >> curl -X GET 'http://localhost:8983/solr/paintings/select?q=*:*&rows=0&facet=true&facet.field=artist_entity&facet.prefix=hen&wt=json'
    
  4. As usual, remember to start the appropriate core first; for example here, I suppose, we have defined a new core in /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.

What just happened?

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.168.163