Using Query Term Completion component in Solr
Posted By : Jasgeet Singh | 01-May-2013
Query Term Completion
One of the most effective features of a search user interface is automatic/instant-search or completion of query input in a search input box. It is typically displayed as a drop-down menu that appears automatically after typing.
Via Suggester:
New in Solr 3 is a high-speed approach to implement term completion, called the Suggester. The Suggester principally features the fastest search performance - handful of milliseconds per search at most.
The following request handler definition just for using the Suggester, goes in solrconfig.xml:
<requestHandler name="/suggest" class="solr.SearchHandler"> <lst name="defaults"> <str name="spellcheck">true</str> <str name="spellcheck.dictionary">a_suggest</str> <str name="spellcheck.onlyMorePopular">true</str> <str name="spellcheck.count">5</str> <str name="spellcheck.collate">true</str> </lst> <arr name="components"> <str>suggest</str> </arr> </requestHandler> <searchComponent name="suggest" class="solr.SpellCheckComponent"> <lst name="spellchecker"> <str name="name">a_suggest</str> <str name="classname"> org.apache.solr.spelling.suggest.Suggester</str> <str name="lookupImpl"> org.apache.solr.spelling.suggest.fst.FSTLookup</str> <str name="field">a_spell</str> <str name="buildOnOptimize">true</str> <int name="weightBuckets">100</int><!-- an FST option --> </lst> </searchComponent>
spellcheck.onlyMorePopular - this parameter means that the results should be sorted by frequency versus alphabetically almost certainly what is desired.
weightBuckets - option is specific to FSTLookup which approximates the frequency of the terms it stores into a discrete set of buckets, defaulting to 10. It can range between 1 and 255. Increasing weightBuckets to 100 or more improves the fidelity of the weights, resulting in more relevant suggestions.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Jasgeet Singh
Jasgeet is a Sr. Lead developer .He is an experienced Groovy and Grails and has worked on designing & developing B2B and B2C portals using Grails technologies.