微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用SolrJ添加搜索组件

如何解决使用SolrJ添加搜索组件

执行代码

我遇到了错误

SolrjsonRequest rq = new SolrjsonRequest(SolrRequest.METHOD.POST,"/config");
String searchComponent = "{\n" +
                "\"add-searchcomponent\":{\n" +
                "    \"name\":\"suggest\",\n" +
                "    \"class\":\"solr.SuggestComponent\",\n" +
                "    \"suggester\":{\n" +
                "        \"name\":\"mySuggester\",\n" +
                "        \"lookupImpl\":\"FuzzyLookupFactory\",\n" +
                "        \"dictionaryImpl\":\"DocumentDictionaryFactory\",\n" +
                "        \"field\":\"suggest\",\n" +
                "        \"suggestAnalyzerFieldType\":\"text_general\"\n" +
                "    }\n" +
                "}\n" +
                "}";

rq.addContentToStream(searchComponent);
rq.process(solrCLient);

如何解决?我需要使用API​​添加一个新的搜索组件。

如果我使用{ "responseHeader":{ "status":500,"QTime":0},"WARNING":"This response format is experimental. It is likely to change in the future.","error":{ "msg":"Expected key,value separator ':': char=(EOF),position=363 AFTER=''","trace":"org.noggit.JSONParser$ParseException: Expected key,position=363 AFTER=''\n\tat org.noggit.JSONParser.err(JSONParser.java:452)\n\tat org.noggit.JSONParser.nextEvent(JSONParser.java:1104)\n\tat org.apache.solr.common.util.CommandOperation.parse(CommandOperation.java:292)\n\tat org.apache.solr.common.util.CommandOperation.readCommands(CommandOperation.java:362)\n\tat ....\n","code":500}} 发送相同的请求,则一切正常。

解决方法

能否请您尝试以下代码?

SolrJsonRequest rq = new SolrJsonRequest(SolrRequest.METHOD.POST,"/config");
String searchComponent = "{\"add-searchcomponent\":{\"name\":\"suggest\",\"class\":\"solr.SuggestComponent\",\"suggester\":{\"name\":\"mySuggester\",\"lookupImpl\":\"FuzzyLookupFactory\",\"dictionaryImpl\":\"DocumentDictionaryFactory\",\"field\":\"suggest\",\"suggestAnalyzerFieldType\":\"text_general\"}}}";

rq.addContentToStream(searchComponent);
rq.process(solrCLient);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。