Auto Complete Suggestions Implementation Using Apache Solr – Approach3

Apache Solr

              In the previous articles, we have seen the auto suggests setup with Apache Solr.  In these days,  the user experience has changed a lot and the way the sites are presenting the auto suggestions to the user is also changed.  Most of the web sites are not presenting the auto suggestions as simple text messages. For example, if you are searching for a movie DVD, they are suggesting film names, along with that they are displaying the thumbnail image of DVD poster, the short description, the cast acted in that movie. So, user is going to get more  information from the auto suggestions.  In the below picture , the suggestions contains popular products with image, price and the film name.

Sample Auto Suggestions

                 If we want to provide the information what we are seeing on the above picture, we need to enhance the configuration which we have done in PART-1 or PART-2. In this example, we are using sample film database and the data is available here.

The analysis configuration provided in the schema.xml is given below.

<fieldType name="text_suggest" class="solr.TextField" positionIncrementGap="100">
   <analyzer type="index">
      <tokenizer class="solr.WhitespaceTokenizerFactory" />
      <filter class="solr.LowerCaseFilterFactory" />
      <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="1000" />
   </analyzer>
   <analyzer type="query">
      <tokenizer class="solr.WhitespaceTokenizerFactory" />
      <filter class="solr.LowerCaseFilterFactory" />
   </analyzer>
</fieldType>
<fieldType name="string" sortMissingLast="true" omitNorms="true" />

The fields configuration provided in the schema.xml is given below.

<fields>
   <field name="id" type="integer" indexed="true" stored="true" required="true" />
   <field name="name" type="text_suggest" indexed="true" stored="true" />
   <field name="image" type="string" stored="true" />
   <field name="filmDesc" type="string" stored="true" />
</fields>

            If you perform search operation for “win” keyword and the response is giving the film names along with thumbnail image and the short description of the film. The sample response is given below.

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <lst name="responseHeader">
      <int name="status">0</int>
      <int name="QTime">94</int>
      <lst name="params">
         <str name="q">name:"win"</str>
      </lst>
   </lst>
   <result name="response" numFound="2" start="0">
      <doc>
         <str name="name">Rear Window (1954)</str>
         <str name="filmDesc">A visceral black-and-white drama about an aging boxer (Robert De Niro), Martin Scorsese's 1980 flick is one of the best of its decade.</str>
         <int name="id">69</int>
         <str name="image">http://www.filmsite.org/covers/ragingb.gif</str>
      </doc>
      <doc>
         <str name="name">Gone With The Wind (1939)</str>
         <str name="filmDesc">Victor Fleming's 1939 star-studded Civil War tour de force finds Clark Gable and Vivien Leigh entangled in a fiery love affair.</str>
         <int name="id">34</int>
         <str name="image">http://www.filmsite.org/covers/graduate.jpg</str>
      </doc>
   </result>
</response>

                 The configuration used in this article is available here. We seen different variations of setup for auto suggestions using Apache Solr. Now, you can implement any of these in your applications.

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
12 comments on “Auto Complete Suggestions Implementation Using Apache Solr – Approach3
  1. Aronsky says:

    Hi, Siva! Thanks for your posts about SOLR Suggestions – I got some bricks from them for understanding the whole picture.
    I have a requirement, which do not know yet how to implement better, maybe you could help me? I need the possibility to show the top categories where the suggestion could me met – like on your picture:

    [god of war in Games]
    [godfather in Books]
    [godfather in Posters]
    [god of small things]
    […]

    Which is the best option to implement this in one query?

  2. Anonymous says:

    Will it works on Solr 4.10 ?

  3. Anonymous says:

    Will it work on Solr 4.10 ???

  4. Anonymous says:

    Wil it work in Solr 4.10 ?

  5. Will it work for solr 3.6.2?

  6. Yesuraj G says:

    Very good explanation. Thanks for your effort.

  7. Anonymous says:

    Nice Explanation.. thanks

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

DZone

DZone MVB

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