Auto Complete Suggestions Implementation Using Apache Solr – Approach2

Apache Solr Auto Suggestions Or Auto Completion          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.

Sample Auto Suggestions

                     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.

https://gist.github.com/2013techsmarts/1109cbd1022d1013f6a6626e8e0f33e5

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.

Advertisement

Siva Janapati is an Architect with experience in building Cloud Native Microservices architectures, Reactive Systems, Large scale distributed systems, and Serverless Systems. Siva has hands-on in architecture, design, and implementation of scalable systems using Cloud, Java, Go lang, Apache Kafka, Apache Solr, Spring, Spring Boot, Lightbend reactive tech stack, APIGEE edge & on-premise and other open-source, proprietary technologies. Expertise working with and building RESTful, GraphQL APIs. He has successfully delivered multiple applications in retail, telco, and financial services domains. He manages the GitHub(https://github.com/2013techsmarts) where he put the source code of his work related to his blog posts.

Tagged with: , , ,
Posted in Apache Solr, Auto Suggestions

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Dzone.com
DZone

DZone MVB

Java Code Geeks
Java Code Geeks
OpenSourceForYou
%d bloggers like this: