TA的每日心情 | 衰 2021-2-2 11:21 |
---|
签到天数: 36 天 [LV.5]常住居民I
|
Suggest配置:打开文件 solrconfig.xml
加入一下代码并且删除以前的:
- <!-- begin-->
- <searchComponent class="solr.SpellCheckComponent" name="suggest">
- <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">suggestion</str>
- <!-- 修改为你要查询的字段 -->
- <float name="threshold">0.0001</float>
- <str name="spellcheckIndexDir">spellchecker</str>
- <str name="comparatorClass">freq</str>
- <str name="buildOnOptimize">true</str>
- <!--<str name="buildOnCommit">true</str>-->
- </lst>
- </searchComponent>
- <requestHandler class="org.apache.solr.handler.component.SearchHandler"
- name="/suggest">
- <lst name="defaults">
- <str name="spellcheck">true</str>
- <str name="spellcheck.dictionary">suggest</str>
- <str name="spellcheck.onlyMorePopular">true</str>
- <str name="spellcheck.extendedResults">false</str>
- <str name="spellcheck.count">10</str>
- <str name="spellcheck.collate">true</str>
- </lst>
- <arr name="components">
- <str>suggest</str>
- </arr>
- </requestHandler>
- <queryConverter name="phraseQueryConverter"
- class="org.apache.solr.spelling.SpellingQueryConverter"/>
-
- <!-- end-->
复制代码 schema.xml加入一下代码:
- <field name="suggestion" type="string" indexed="true" stored="true" termVectors="true" multiValued="true"/>
复制代码
测试查询:
测试java代码:
- SolrQuery query = new SolrQuery();
- query.set("q", "quesContent:"+word);//查询的词
- query.set("qt", "/suggest");//请求到suggest中
- query.set("spellcheck.count", "10");//返回数量
- QueryResponse rsp = server.query(query);
- //上面取结果的代码
- SpellCheckResponse re=rsp.getSpellCheckResponse();//获取拼写检查的结果集
- JSONArray array = new JSONArray();
- if (re != null) {
- for(Suggestion s:re.getSuggestions()){
- List<String> list=s.getAlternatives();//获取所有 的检索词
- for(String spellWord:list){
- JSONObject obj = new JSONObject();
- obj.put("title", spellWord);
- array.put(obj);
- }
- }
- }
复制代码
|
|