Solr:从查询响应中获取排序规则
我正在尝试配置 SOLR 拼写检查。我的请求和响应似乎运行良好。唯一的问题是我如何从响应中获取排序规则。
这是我的回复中包含整理的部分。 我使用 API 中的哪些方法来提取 3 个排序规则。
<str name="collation">ipod tough</str>
<str name="collation">ipad tough</str>
<str name="collation">wood tough</str>
<str name="collation">food tough</str>
这是我当前使用的方法:
List<String> suggestedTermsList = new ArrayList<String>();
if(aQueryResponse == null) {
return suggestedTermsList;
}
try {
SpellCheckResponse spellCheckResponse = aQueryResponse.getSpellCheckResponse();
if(spellCheckResponse == null) {
throw new Exception("No SpellCheckResponse in QueryResponse");
}
List<Collation> collationList = spellCheckResponse.getCollatedResults();
for(Collation c : collationList){
suggestedTermsList.add(c.getCollationQueryString());
}
}catch(Exception e) {
Trace.Log("SolrSpellCheck",Trace.HIGH, "Exception: " + e.getMessage());
}
return suggestedTermsList;
我的响应标头如下所示:
spellcheck={suggestions={ipood={numFound=5,startOffset=0,endOffset=5,suggestion=[ipod, ipad, wood, food, pod] },collation=ipodough,collation=ipadtough,collation=woodtough,collation=foodtough}}}
我得到 4 个排序规则,我想将其添加到列表 suggestTermsList 中然后我返回到调用代码。现在我的 ArrayList 有 4 个排序规则,但它只有最后一个排序规则重复了 4 次。即食物很难吃-四次。
Im trying to configure SOLR spell checking. My request and response seem to be working fine. Only problem is how do i get the Collations from the response.
This is the part of my response that has the collations.
What methods in the API do i use to extract the 3 collations.
<str name="collation">ipod tough</str>
<str name="collation">ipad tough</str>
<str name="collation">wood tough</str>
<str name="collation">food tough</str>
This is the method that im using currently:
List<String> suggestedTermsList = new ArrayList<String>();
if(aQueryResponse == null) {
return suggestedTermsList;
}
try {
SpellCheckResponse spellCheckResponse = aQueryResponse.getSpellCheckResponse();
if(spellCheckResponse == null) {
throw new Exception("No SpellCheckResponse in QueryResponse");
}
List<Collation> collationList = spellCheckResponse.getCollatedResults();
for(Collation c : collationList){
suggestedTermsList.add(c.getCollationQueryString());
}
}catch(Exception e) {
Trace.Log("SolrSpellCheck",Trace.HIGH, "Exception: " + e.getMessage());
}
return suggestedTermsList;
My response header is like so:
spellcheck={suggestions={ipood={numFound=5,startOffset=0,endOffset=5,suggestion=[ipod, ipad, wood, food, pod]},collation=ipod tough,collation=ipad tough,collation=wood tough,collation=food tough}}}
I get 4 collations which I want to add to a List suggestedTermsList which I then return to the calling code. Right now my ArrayList has 4 collations but it only has the last collation repeated 4 times. i.e food tough - four times.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想你想调用 QueryResponse.getSpellCheckResponse() 并从那里开始。以下是一些可能对您有用的文档链接:
http://lucene.apache.org/solr/api/org/apache/solr/client/solrj/response/SpellCheckResponse.Collation.html
http://lucene.apache .org/solr/api/index.html?org/apache/solr/client/solrj/response/SpellCheckResponse.html
I think you want to call QueryResponse.getSpellCheckResponse() and go from there. Here are some links to documentation you might find helpful:
http://lucene.apache.org/solr/api/org/apache/solr/client/solrj/response/SpellCheckResponse.Collation.html
http://lucene.apache.org/solr/api/index.html?org/apache/solr/client/solrj/response/SpellCheckResponse.html