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={su开发者_开发百科ggestions={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.
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
精彩评论