您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要介绍“solr4.7智能提示怎么实现”,在日常操作中,相信很多人在solr4.7智能提示怎么实现问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”solr4.7智能提示怎么实现”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
solrconfig.xml配置:
<searchComponent name="suggest" class="solr.SpellCheckComponent"> <!-- <str name="queryAnalyzerFieldType">text_general</str> --> <lst name="spellchecker"> <str name="name">suggest</str> <str name="classname">org.apache.solr.spelling.suggest.Suggester</str> <str name="lookupImpl">org.apache.solr.spelling.suggest.tst.TSTLookup</str> <str name="field">text</str> <float name="threshold">0.0001</float> <str name="comparatorClass">freq</str> <str name="buildOnOptimize">true</str> <str name="buildOnCommit">true</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">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智能提示怎么实现”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。