[英]Add search component using 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=''\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}}
如何解決? 我需要使用 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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.