我正在尝试使用java从Solr获取建议者响应,但是每次运行代码时我都无法获得resposne。 代码:
SolrClient solrClient=new HttpSolrClient.Builder("http://localhost:/solr/core/").build();
SolrQuery sq = new SolrQuery();
sq.setRequestHandler("/suggest");
sq.set("suggest","true");
sq.set("suggest.build","true");
sq.set("suggest.dictionary","mySuggester");
sq.set("suggest.q",name);
QueryResponse rsp = solrClient.query(sq);
System.out.println(rsp.getSuggesterResponse().getSuggestedTerms());
List<String> types=rsp.getSuggesterResponse().getSuggestedTerms().get("mySuggester");
System.out.println(types);
但是当我使用以下命令在Solr UI中运行查询url时: http://localhost:8983/solr/core/suggest?suggest.dictionary=mySuggester&suggest.q=stack&suggest=true&wt=json,我以(示例):
的形式得到输出{"responseHeader":{"status":0,"QTime":119},"suggest":{"mySuggester":{"stack":{"numFound":2,"suggestions":[{"term":"<b>Stack</b>overfolw","weight":0,"payload":""},{"term":"<b>Stack</b>overfolw advanced","weight":0,"payload":""}]}}}}
当我使用solrJ代码获取建议的术语时,我得到[ Stack overfolw advanced, Stack overfolw advanced],有时只是[]。
我不明白为什么会出现这个问题。
提前致谢