Solr:从查询响应中获取排序规则

发布于 2024-12-05 19:36:49 字数 1369 浏览 9 评论 0原文

我正在尝试配置 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] },collat​​ion=ipodough,collat​​ion=ipadtough,collat​​ion=woodtough,collat​​ion=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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文