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.

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.

         e laptop
         laptop a
         hp laptop laptop
         lap rest for laptop
         lap tray laptop
         laptop case laptop
         laptop laptop
         laptop laptop bag
         laptop on your lap

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.


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( 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: Logo

You are commenting using your 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.


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