本文介绍了带有 Solr 建议器的 Solrj的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 Solr Suggester 从 solrj 获取结果的正确方法是什么?
What is the correct way of getting results from solrj using Solr Suggester?
这是我的要求:
SolrQuery query = new SolrQuery();
query.setRequestHandler("/suggest");
query.setParam("suggest", "true");
query.setParam("suggest.build", "true");
query.setParam("suggest.dictionary", "mySuggester");
query.setParam("suggest.q", "So");
QueryResponse response = server.query(query);
但是我发现很难得到回应.我得到回应的方式是这样的:
However I found it extremely difficult to get the response. The way I got the response is with this:
NamedList obj = (NamedList)((Map)response.getResponse().get("suggest")).get("mySuggester");
SimpleOrderedMap obj2 = (SimpleOrderedMap) obj.get("So");
List<SimpleOrderedMap> obj3 = (List<SimpleOrderedMap>) obj2.get("suggestions");
这似乎对我从响应中得到的对象做了很多假设,并且很难预测错误.
This seems to assume a lot about the objects I am getting from the response and will be difficult to anticipate errors.
还有比这更好更干净的方法吗?
Is there a better and cleaner way than this?
推荐答案
在新版本中有一个 SuggesterResponse:
In new versions have a SuggesterResponse:
这篇关于带有 Solr 建议器的 Solrj的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!