Solr/SolrJ 版本:6.0.0
我已经在 solrconfig.xml 中设置了 termvector 组件,请求处理程序是“/tvrh”,我在浏览器中测试了它,这有效。现在我想在solrJ中使用它,但它只返回文档。以下是我的代码:
SolrClient solrClient = new HttpSolrClient("http://localhost:8983/solr/test");
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQuery(String.format("id:%s","clueweb12-0000tw-06-17744"));
solrQuery.setRequestHandler("/tvrh");
solrQuery.set("tv", true);
solrQuery.set("tv.all", true);
QueryResponse response = solrClient.query(solrQuery);
SolrDocumentList docs = response.getResults();
for (SolrDocument doc: docs){
for (String key: doc.keySet()){
System.out.println(key);
System.out.println(doc.getFieldValue(key));
}
}
最佳答案
您的问题是如何在 solr 中使用非标准请求处理程序。
请注意,术语 vector 组件属于“非标准”请求处理程序,并且不受 solrj 支持: https://cwiki.apache.org/confluence/display/solr/The+Term+Vector+Component#TheTermVectorComponent-SolrJandtheTermVectorComponent
您可以在通用模式下通过 solrj 调用“/tvrh”。您不能为此使用 SolrClient#query(SolrParams params) 方法,因为在这种情况下,“请求处理程序”仅作为“qt”参数发送,并且不会成为 url 路径的一部分(并且 qt 参数是默认忽略)。
所以请尝试使用“SolrClient#request”方法。
关于java - 如何在solrJ中使用termVector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41460037/