使用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);

我得到错误

{
"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,value separator ':': char=(EOF),position=363 AFTER=''ntat org.noggit.JSONParser.err(JSONParser.java:452)ntat org.noggit.JSONParser.nextEvent(JSONParser.java:1104)ntat org.apache.solr.common.util.CommandOperation.parse(CommandOperation.java:292)ntat org.apache.solr.common.util.CommandOperation.readCommands(CommandOperation.java:362)ntat ....n",
"code":500}}

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

如果我使用RestTemplate发送相同的请求,一切都很好。

你能试试下面的代码吗?

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

最新更新