gpt4 book ai didi

java - 使用 "org.apache.solr.common.util.SimpleOrderedMap cannot be cast to java.util.Map"处理程序时出现 solrj "/suggest"异常

转载 作者:太空宇宙 更新时间:2023-11-04 09:48:33 25 4
gpt4 key购买 nike

尝试使用/suggest 处理程序运行 solrj 程序时,出现类转换异常。我能够从 Solr 管理 UI 获得建议响应,但是当从 solrj 客户端尝试相同的操作时,会出现上述异常。

solr-config.xml 条目如下:

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

schema.xml 包含字段

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

这是多个字段的 copyField。

java代码如下:

 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());

异常(exception)情况如下:

 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)

最佳答案

我不确定为什么它设置 XMLResponseParser 然后请求 wt=json。我认为https://github.com/apache/lucene-solr/blob/master/solr/solrj/src/test/org/apache/solr/client/solrj/response/TestSuggesterResponse.java可以用作开始的示例。

关于java - 使用 "org.apache.solr.common.util.SimpleOrderedMap cannot be cast to java.util.Map"处理程序时出现 solrj "/suggest"异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55115760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com