Controlling the number of terms needed to match
Imagine a situation where you have an e-commerce bookstore and you want to make a search algorithm that tries to bring the best search results to your customers. However, you notice that many of your customers tend to make queries with too many words, which results in an empty result list. So, you decide to make a query that will require a maximum of two of the words, which the user entered, to be matched. This recipe will show you how to do it.
Getting ready
Before we continue, it is crucial to mention that the following method can only be used with the dismax
or edismax
query parser. For the list of available query parsers, refer to http://wiki.apache.org/solr/QueryParser.
How to do it...
Follow these steps to control the number of terms needed to match:
Let's begin with creating our index structure. For our simple use case, we will only have documents with the identifier (the
id
field) and title (thetitle
field). We define the index structure...