首页 技术 正文
技术 2022年11月16日
0 收藏 876 点赞 3,199 浏览 2313 个字

目录

回到顶部

配置文件

  • solrconfig.xml
  <searchComponent name="suggest" class="solr.SpellCheckComponent">     <str name="queryAnalyzerFieldType">string</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">hot_word</str> <!-- 设定需要智能提示词的字段名 -->
<float name="threshold">0.00001</float> <!-- 设定频率:自我解释为:你现在的商品数量,占商品总数的百分比,
低于你配置的百分比就不会被suggest检索
你配置的低一点,那么商品数量较少的那部分商品就会被你检索出来-->
<!-- 使用自定义suggest词库词可以将如下两行的注释取消
<str name="sourceLocation">suggest.txt</str>
<str name="spellcheckIndexDir">spellchecker</str>
-->
<str name="comparatorClass">freq</str>
<str name="buildOnOptimize">true</str>
<str name="buildOnCommit">true</str>
</lst>
</searchComponent> <requestHandler name="/suggest" class="org.apache.solr.handler.component.SearchHandler">
<lst name="defaults">
<str name="spellcheck">true</str>
<str name="spellcheck.dictionary">suggest</str>
<str name="spellcheck.count"></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>
  • schema.xml

我需要智能提示的字段为商品名,我没有在原来的基础上进行智能匹配词,又创建了一个类型为String的字段。

由于ik是分词,所以重新定义了一个。可以试试类型为IK分词的。看一下效果。

   <field name="hmp_name" type="text_ik" indexed="true" stored="true"/>
<field name="hot_word" type="string" indexed="true" stored="true"/>

回到顶部

Java代码

@Override
public JSONObject suggestHotWordList(String hotword) throws Exception
{
JSONObject msgJson = new JSONObject();
List<String> wordList=new ArrayList<String>();
SolrQuery query = new SolrQuery();
query.set("q", "hot_word:"+hotword);//查询的词 query.set("qt", "/suggest");//请求到suggest中 query.set("spellcheck.count", "");//返回数量 QueryResponse queryResponse = solrServer.query(query); //获取拼写检查的结果集
SpellCheckResponse re=queryResponse.getSpellCheckResponse(); if (re != null)
{
for(Suggestion s : re.getSuggestions())
{
List<String> list = s.getAlternatives();//获取所有 的检索词
for(String spellWord : list)
{
wordList.add(spellWord);
}
}
}
msgJson.put("numFound", wordList.size());
msgJson.put("hotwords", wordList);
return msgJson;
}

回到顶部

遇到的问题

遇到的问题:有的词可以匹配出来。有的词存在,确匹配不出来。那就是有可能是因为频率不够。

自己的理解:就是说,你现在的商品数量,占商品总数的百分比,低于你配置的百分比就不会被suggest检索,你配置的低一点,那么商品数量较少的那部分商品就会被你检索出来。

也就是上面配置文件中,提到的。 0.00001..

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,580
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918