尝试使用/ suggest处理程序运行solrj程序时,我得到了类强制转换异常。我能够从Solr Admin 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 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可以作为开始的样本。
为建议者使用多值字段是否有意义?它建议哪一个? copyField指令将在一个字段中放置多个文本块。
你想要什么结果?这个设计对我来说没有意义。