这篇文章主要介绍“solr4.7智能提示怎么实现",在日常操作中,相信很多人在solr4.7智能提示怎么实现问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答“solr4.7智能提示怎么实现"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
solrconfig.xml配置:
搜索组件名=' improve ' class=' Solr ."拼写检查组件"
!-strname=' querylyzerfieldtype ' text _ general/str-
lstname='拼写检查器'
strname='name '建议/str
strname=' class name ' org。阿帕奇。索尔。拼写。暗示。暗示者/str
strname=' lookupImpl ' org。阿帕奇。索尔。拼写。建议。tst。tstlookp/str
strname='field'text/str
floatname="阈值“0.0001/浮动
strname=' comparatorClass ' freq/str
strname=' BuildOnOptimize ' true/str
strname=' buildOnCommit ' true/str
/lst
/searchComponent
request handler name='/improve ' class=' Solr ." SearchHandler "
lstname="默认值"
strname="拼写检查" true/str
strname='spellcheck.dictionary '建议/str
s
tr name="spellcheck.count">10</str>
<str name="spellcheck.onlyMorePopular">true</str>
<str name="spellcheck.extendedResults">false</str>
<str name="spellcheck.collate">true</str>
<!--<str name="spellcheck.build">true</str> -->
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>
solrj代码:
/** * @method: spellcheck * @Description: 智能提示 * Solr里叫做Suggest模块 * * @return void * * @author: ChenYW * @date 2014-4-15 下午04:29:24 */ public List<Map<String, String>> suggest(String word) { List<Map<String, String>> wordList = new ArrayList<Map<String, String>>(); try { SolrQuery query = new SolrQuery(); query.set("q", "text:" + word);//查询的词 query.set("qt", "/suggest");//请求到suggest中 query.set("spellcheck.count", "10");//返回数量 QueryResponse rsp = server.query(query); //上面取结果的代码 SpellCheckResponse re = rsp.getSpellCheckResponse();//获取拼写检查的结果集 if (re != null) { for (Suggestion s : re.getSuggestions()) { List<String> list = s.getAlternatives();//获取所有 的检索词 for (String spellWord : list) { Map<String, String> map = new HashMap<String, String>(); map.put("code", spellWord); wordList.add(map); } } String t = re.getFirstSuggestion(word);//获取第一个推荐词 } } catch (Exception e) { e.printStackTrace(); } return wordList; }
到此,关于“solr4.7智能提示怎么实现”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!
内容来源网络,如有侵权,联系删除,本文地址:https://www.230890.com/zhan/155612.html