I have configured Suggester in Solr and by using the below URL i am able to
get the results.

http://localhost:8983/solr/collection1/suggest?suggest=true&suggest.build=true&suggest.dictionary=mySuggester&suggest.q=Mo

But to achieve the same with SolrJ code I am getting the below exception at
line 7 of further below snippet.

Exception in thread "main" java.lang.ClassCastException:
org.apache.solr.common.util.SimpleOrderedMap cannot be cast to java.util.Map
at
org.apache.solr.client.solrj.response.QueryResponse.setResponse(QueryResponse.java:161)
at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:178) at
org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:942) at
org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:957) at
com.finder.testsearch.SolrJBeanSearcher.main(SolrJBeanSearcher.java:71)

Code:

SolrQuery suggestionQuery = new SolrQuery();
suggestionQuery.setRequestHandler("/suggest");
suggestionQuery.set("suggest", "true");
suggestionQuery.set("suggest.build", "true");
suggestionQuery.set("suggest.dictionary", "mySuggester");
suggestionQuery.set("suggest.q", "Hom");
QueryResponse suggestionResponse = solr.query(suggestionQuery);

SuggesterResponse suggesterResponse = 
suggestionResponse.getSuggesterResponse();
Map<String,List&lt;String>> suggestedTerms = 
suggesterResponse.getSuggestedTerms();
List<String> suggestions = suggestedTerms.get("mySuggester");
Below are solrconfig.xml entries.

<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
  <str name="name">mySuggester</str>
  <str name="lookupImpl">FuzzyLookupFactory</str>
  <str name="dictionaryImpl">DocumentDictionaryFactory</str>
  <str name="field">tagsList</str>
  <str name="suggestAnalyzerFieldType">string</str>
  <str name="buildOnStartup">false</str>
</lst>
</searchComponent>

<requestHandler name="/suggest" class="solr.SearchHandler"
                  startup="lazy" >
  <lst name="defaults">
  <str name="suggest">true</str>
  <str name="suggest.count">10</str>
</lst>
<arr name="components">
  <str>suggest</str>
</arr>
</requestHandler>
Any suggestions.

Thanks.



--
Sent from: http://lucene.472066.n3.nabble.com/Lucene-Java-Developer-f564358.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to