1

I am trying to implement Solr suggester. I am able to fetch the response from Solr, but unable to extract only the suggested terms out of the response.

Response looks like:

{
  "responseHeader":{
    "status":0,
    "QTime":1},
  "suggest":{"mySuggester":{
      "agi":{
        "numFound":2,
        "suggestions":[{
            "term":"IGADC_T200_<b>Agi</b>le-Planning-and-Estimation",
            "weight":0,
            "payload":""},
          {
            "term":"IGADC_T200_<b>Agi</b>leOverview",
            "weight":0,
            "payload":""}]}}}}

How can I fetch only the terms out of this response.

SolrQuery sq = new SolrQuery();
sq.setRequestHandler("/suggest");
    sq.set("suggest.dictionary", "mySuggester");
    sq.set("suggest.q",keyword);
    sq.set("suggest",true);
    sq.set("suggest.build", "true");
    sq.set("suggest.count",10);

I tried using :

SpellCheckResponse spellCheckResponse = response.getSpellCheckResponse();

but it returns null, even though my response contains the suggestions.

Thanks in advance.

Lefty G Balogh
  • 1,771
  • 3
  • 26
  • 40
arun abraham
  • 147
  • 2
  • 12
  • From 5.something the SuggestResponse was introduced: https://lucene.apache.org/solr/6_2_0/solr-solrj/org/apache/solr/client/solrj/response/SuggesterResponse.html – MatsLindh Oct 13 '16 at 19:19
  • Can u explain how to use SuggesterResponse to get the suggested terms from the response – arun abraham Oct 14 '16 at 03:48
  • If you follow the API documentation above, you can see that the SuggerResponse has a `getSuggestions` (or the simpler `getSuggestedTerms` method), that returns a Map with a list of Suggestion objects for each term to suggest something for. This Suggstion object contains the weight, term (string) and payload for each term that has been suggested for the inputted term. – MatsLindh Oct 14 '16 at 16:39
  • Thanks for the reply. – arun abraham Oct 17 '16 at 10:20

0 Answers0