In the PART-1 post, we discussed the basic setup to get the auto suggestions starting with the search keyword. In this article, we will discuss how to configure Apache Solr to get the auto-suggestions based on the search keyword that appears at any position. For example, If user is typing for “lap“, we need to provide “laptop computers”, “dell laptop”, “hp laptop” etc as auto-suggestions. If you look at the suggestions, the suggestions are not only the words starting with “lap“, but also the suggestions having “lap” at any position. The below picture depicts the same.
To achieve the same thing what we are seeing in the above picture, we need to change the analysis part in the schema.xml (In part-1 we discussed the setup, here we are enhancing the part-1 configuration). The configuration is given below.
Do the full import of the data. Once the full import is done, perform some searches to get the auto-suggestions.
For example, try to get the auto suggestions for key word “lap“, http://<host name>:<port>/solr/autoSuggestApproach2/select?q=term:”lap”&wt=xml&indent=true&rows=10
The response is given below.
0 0 term:"lap" 10 e laptop 3228 laptop a 5180 laptops 5510 hp laptop laptop 4339 lap rest for laptop 5149 lap tray laptop 5152 laptop case laptop 5282 laptop laptop 5410 laptop laptop bag 5411 laptop on your lap 5433
The above response is having the auto suggestions having “lap” keyword at any position. we can use this to present the auto suggestions/ auto-completion feature in the site.
The Solr setup used in this article is available here.
Leave a Reply