solr 使用 suggest 自动 提示,查询不到结果 SpellCheckComponent
@震秦 你好,想跟你请教个问题:
@震秦 你好,想跟你请教个问题:
<!-- mm suggest,, copyField is merge field a to dest=ab--> <searchComponent name="suggest" class="solr.SpellCheckComponent"> <str name="queryAnalyzerFieldType">textSpell</str> <lst name="spellchecker"> <str name="name">direct</str> <str name="field">productName</str> <str name="classname">solr.DirectSolrSpellChecker</str> <str name="distanceMeasure">internal</str> <float name="accuracy">0.5</float> <int name="maxEdits">2</int> <int name="minPrefix">1</int> <int name="maxInspections">5</int> <int name="minQueryLength">4</int> <float name="maxQueryFrequency">0.01</float> <!--<str name="sourceLocation">dict.txt</str>--> <!--if appoint the sourceLocation,the field is not work--> </lst> </searchComponent>
<!--mm suggest--> <requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy"> <lst name="defaults"> <str name="df">text</str> <str name="spellcheck.dictionary">direct</str> <str name="spellcheck">on</str> <str name="spellcheck.extendedResults">true</str> <str name="spellcheck.count">10</str> <str name="spellcheck.collate">true</str> <str name="spellcheck.collateExtendedResults">true</str> </lst> <arr name="last-components"> <str>suggest</str> </arr> </requestHandler>
solrj 调用
HttpSolrServer solrServer =SolrServer.getInstance().getServer(); solrServer.setRequestWriter(new BinaryRequestWriter()); SolrQuery sQuery = new SolrQuery(); ModifiableSolrParams params=new ModifiableSolrParams(); params.set("qt", "/suggest");//spellhandler params.set("q",content); ///CommonParams.QT 条件命名 params.set("spellcheck", "on"); params.set("spellcheck.build", "true"); params.set("spellcheck.count", "10"); //params.set("spellcheck.alternativeTermCount", "4"); // params.set("spellcheck.onlyMorePopular", "false"); //params.set("spellcheck.extendedResults", "false"); // params.set("spellcheck.maxResultsForSuggest", "5"); //params.set("spellcheck.collate", "true"); // params.set("spellcheck.collateExtendedResults", "true"); //params.set("spellcheck.maxCollationTries", "5"); //params.set("spellcheck.maxCollations", "3"); sQuery.add(params); try { // 第一种方式 获得 entitylist QueryResponse response = solrServer.query(sQuery); SpellCheckResponse spellCheckResponse = response.getSpellCheckResponse(); if(spellCheckResponse != null){ List<Suggestion> suggestionList=spellCheckResponse.getSuggestions(); for(Suggestion suggestion:suggestionList){ if(suggestion.getNumFound()!=0){ List<String> suggestWordList=suggestion.getAlternatives(); JsonMapper jsonMapper=JsonMapper.awalysMapper(); String json = jsonMapper.toJson(suggestWordList); HttpServletResponse response1=ServletActionContext.getResponse(); response1.setContentType("text/plain"); response1.setCharacterEncoding("UTF-8"); PrintWriter out=response1.getWriter(); out.print(json); out.flush(); out.close(); break; } } }
List<Suggestion> suggestionList=spellCheckResponse.getSuggestions(); 没有任何 suggestion返回 。。
怎么办 ,求教
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以用这个方法,queryResponse.getSuggestion()
你好,这个问题解决了吗?