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.


   
      
      
      
   
   
      
      
   

The fields 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.

Advertisements

I am Siva Prasad Rao Janapati. Working as a software developer. Has hands on experience on ATG Commerce(DAS/DPS/DCS), Mozu commerce, Broadleaf Commerce, Java, JEE, Spring, Play, JPA, Hibernate, Velocity, JMS, Jboss, Weblogic,Tomcat, Jetty, Apache, Apache Solr, Spring Batch, JQuery, NodeJS, SOAP, REST, MySQL, Oracle, Mongo DB, Memcached, HazelCast, Git, SVN, CVS, Ant, Maven, Gradle, Amazon Web services, Rackspace, Quartz, JMeter, Junit, Open NLP, Facebook Graph,Twitter4J, YouTube Gdata, Bazzarvoice,Yotpo, 4-Tell, Alatest, Shopzilla, Linkshare. I have hands on experience on open sources and commercial technologies.

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 )

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s

DZone

DZone MVB

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