solrj “org.apache.solr.common.util.SimpleOrderedMap cannot be cast to java.util.Map” exception when using “/suggest” handler

匿名 (未验证) 提交于 2019-12-03 01:41:02

问题:

I get the class cast exception when trying to run the solrj program using /suggest handler. I am able to get the suggestion response from Solr Admin UI, but when the same is being tried from solrj client the above exception arises.

The solr-config.xml entries are as follows :

 <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">suggestfield</str>             <str name="suggestAnalyzerFieldType">text_general</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>         <str name="suggest.dictionary">mySuggester</str>     </lst>     <arr name="components">             <str>suggest</str>     </arr>   </requestHandler> 

The schema.xml contains the field

<field name="suggestfield" type="text_general" indexed="true" stored="true"/> 

which is a copyField of multiple fields.

The java code is as follows :

 String url = "http://localhost:8983/solr/testwidget";      HttpSolrClient client = new HttpSolrClient.Builder(url).build();     client.setParser(new XMLResponseParser());      SolrQuery query = new SolrQuery();     query.setRequestHandler("/suggest");     query.setParam("suggest.build", true);     query.setParam("suggest", true);     query.setParam("suggest.dictionary", "mySuggester");     query.setParam("suggest.q", "acc");      QueryResponse response = client.query(query);   System.out.println(response.getSuggesterResponse().getSuggestedTerms()); 

The exception is as follows :

 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:194)     at org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:942)     at org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:957)     at com.intellectdesign.canvas.solr.SolrjTest.main(SolrjTest.java:41) 

回答1:

I'm not sure why it set XMLResponseParser and then request wt=json. I think https://github.com/apache/lucene-solr/blob/master/solr/solrj/src/test/org/apache/solr/client/solrj/response/TestSuggesterResponse.java may be used as a sample for beginning.



回答2:

Does it make any sense to use a multivalued field for a suggester? Which one does it suggest? The copyField directive will put multiple chunks of text in a single field.

What result do you want? This design doesn't make sense to me.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!