SOLR Smart Tips (suggest)

Source: Internet
Author: User
Tags solr

E-commerce search in order to achieve such a function, when the input text, drop-down box prompt. Similar to Baidu search


In the Lucene-based SOLR search engine, where the division is famous. Provides this feature for spell checking and smart hints.

The spelling checker is used to check whether a user's input is present or not, and if it doesn't exist, give it a hint of something similar, or anything like it.

The search suggestion is that after the user enters a search condition, it will give a series of prompt content immediately, and recommend the first appearance similar words, as the recommendation Word.

That is, the spelling checker can be used as a separate feature, but suggest generally refers to spelling check pieces

Implementation process, configuration Solrconfig.xml

  <searchcomponent name= "suggest" class= "SOLR. Spellcheckcomponent "> <!--<str name=" Queryanalyzerfieldtype ">text_general</str>-<l St Name= "spellchecker" > <str name= "name" >suggest</str> <str name= "ClassName" >or g.apache.solr.spelling.suggest.suggester</str> <str name= "Lookupimpl" >org.apache.solr.spelling.sugg est.tst.tstlookup</str> <str name= "field" >article</str> <float name= "threshold" >0          .0001</float> <!--Use the custom suggest Word store Word to cancel the comments of the following two lines <str name= sourcelocation >suggest.txt</str> <str name= "Spellcheckindexdir" >spellchecker</str>--> <str name= "Comparatorclass" >f req</str> <str name= "buildonoptimize" >true</str> <str name= "Buildoncommit" >true& lt;/str> </lst> </searchComponent> <requesthandler name= "/suGgest "class=" SOLR.            Searchhandler "> <lst name=" Defaults "> <str name=" spellcheck ">true</str>            <str name= "Spellcheck.dictionary" >suggest</str> <str name= "Spellcheck.count" >11</str> <str name= "Spellcheck.onlymorepopular" >true</str> <str name= "Spellcheck.extendedresults" >false</str> <str name= "Spellcheck.collate" >true</str> <!--<str Name= "s Pellcheck.build ">true</str> </lst> <arr name=" Components "> &LT;STR&G T;suggest</str> </arr> </requestHandler>

Restart the SOLR service. Executing SOLRJ client code

/** * @method: SpellCheck * @Description: Smart tips in SOLR called suggest module */public static list< Map<string, string>> suggest (String word,string corename) {solrserver server=indexer.gethttpsolrserver ( Corename); list<map<string, string>> wordList = new arraylist<map<string, string>> (); try {SolrQuery query = new Solrquery (); Query.set ("Q", word);//Query the word query.set ("qt", "/suggest");//request to suggest//query.set (" Spellcheck.count "," "");//return quantity queryresponse RSP = server.query (query);//The code above results Spellcheckresponse re = Rsp.getspellcheckresponse ();//Gets the result set of the spelling check if (re! = null) {for (Suggestion S:re.getsuggestions ()) {list<string> Li  st = S.getalternatives ();//Gets all the search terms for (String spellword:list) {map<string, string> Map = new hashmap<string, String> (); Map.put ("Code", Spellword); Wordlist.add (map);}} String t = re.getfirstsuggestion (WORD);//Gets the first recommended word}} catch (Exception e) {e.printstacktrace ();} return wordList;} 

Simple Front End:



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

SOLR Smart Tips (suggest)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.