首页 文章

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

提问于
浏览
1

我试图配置SOLR拼写检查 . 我的请求和响应似乎工作正常 . 唯一的问题是如何从响应中获取Collations .

这是我的回复中包含排序规则的部分 . 我使用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;

我的响应 Headers 是这样的:

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}}}

我得到4个归类,我想添加到List suggestedTermsList,然后我返回到调用代码 . 现在我的ArrayList有4个排序规则,但它只重复最后一次排序4次 . 即食物坚韧 - 四次 .

1 回答

相关问题