【问题标题】:Solr : Getting Collations from a query responseSolr:从查询响应中获取排序规则
【发布时间】:2011-09-22 12:03:59
【问题描述】:

我正在尝试配置 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=ipod 坚韧,collat​​ion=ipad 坚韧,collat​​ion =wood 坚韧,collat​​ion=food 坚韧}}}

我得到了 4 个排序规则,我想将它们添加到 ListSuggestedTermsList 中,然后我将其返回给调用代码。现在我的 ArrayList 有 4 个排序规则,但它只有最后一个排序规则重复了 4 次。即食物坚韧 - 四次。

【问题讨论】:

  • 你没有说你正在使用什么客户端 API,或者你是如何读取响应的。你在使用 SolrJ 吗?
  • 嗨迈克,请看看我更新的问题。
  • 嗯,这似乎很奇怪。我还没有听说过这样的错误。您确定您没有在此处未向我们展示的外层中错误地报告它们吗?
  • 我最终添加了 spellcheck.collat​​eExtendedResults = true 并且它返回了正确的排序规则。我从 lucene 论坛得到了帮助。 lucene.472066.n3.nabble.com/…

标签: solr spell-checking collation


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-10
    • 1970-01-01
    • 1970-01-01
    • 2013-09-26
    • 2013-09-12
    • 1970-01-01
    • 2019-05-11
    • 1970-01-01
    相关资源
    最近更新 更多