How to realize solr4.7 Smart Tip
This article mainly introduces "how to realize solr4.7 intelligent prompt". In daily operation, I believe many people have doubts about how to realize solr4.7 intelligent prompt. Xiaobian consulted all kinds of materials and sorted out simple and easy operation methods. I hope to help you answer the doubts of "how to realize solr4.7 intelligent prompt"! Next, please follow the small series to learn together!
solrconfig.xml Configuration:
suggest org.apache.solr.spelling.suggest.Suggester org.apache.solr.spelling.suggest.tst.TSTLookup text 0.0001 freq true true true suggest 10 true false true suggest
Solrj Code:
/** * @method: spellcheck * @Description: Smart Tips * Solr is called Suggest module * * @return void * * @author: ChenYW * @date 2014-4-15 PM 04:29:24 */ public List suggest(String word) { List wordList = new ArrayList(); try { SolrQuery query = new SolrQuery(); query.set("q", "text:" + word);//query word query.set("qt", "/suggestion");//request to suggestion query.set("spellcheck.count", "10");//Returns the number QueryResponse rsp = server.query(query); //code above to get results SpellCheckResponse re = rsp.getSpellCheckResponse();//Get the result set for spell checking if (re != null) { for (Suggestion s : re.getSuggestions()) { List list = s.getAlternatives();//Get all search terms for (String spellWord : list) { Map map = new HashMap(); map.put("code", spellWord); wordList.add(map); } } String t = re.getFirstSuggestion(word);//Get the first recommendation word } } catch (Exception e) { e.printStackTrace(); } return wordList; } At this point, the study of "how to realize solr4.7 intelligent prompt" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!