Java Solr SearchComponent获取所有文档
我正在编写一个solr插件(SearchComponent),并希望迭代查询中找到的所有文档。这是我在process方法中的代码部分:Java Solr SearchComponent获取所有文档,java,solr,Java,Solr,我正在编写一个solr插件(SearchComponent),并希望迭代查询中找到的所有文档。这是我在process方法中的代码部分: // Searcher to search a document SolrIndexSearcher searcher = rb.req.getSearcher(); // Getting the list of documents found for the query DocList docs = rb.getResults
// Searcher to search a document
SolrIndexSearcher searcher = rb.req.getSearcher();
// Getting the list of documents found for the query
DocList docs = rb.getResults().docList;
// Return if no results are found for the query
if (docs == null || docs.size() == 0) {
return;
}
// Get the iterator for the documents that will be returned
DocIterator iterator = docs.iterator();
// Iterate over all documents and count occurrences
for (int i = 0; i < docs.size(); i++) {
try {
// Getting the current document ID
int docid = iterator.nextDoc();
// Fetch the document from the searcher
Document doc = searcher.doc(docid);
// do stuff
} catch (Exception e) {
LOGGER.error(e.getMessage());
}
}
//搜索者搜索文档
solrindexearcher searcher=rb.req.getSearcher();
//获取为查询找到的文档列表
DocList docs=rb.getResults().DocList;
//如果找不到查询的结果,则返回
如果(docs==null | | docs.size()==0){
返回;
}
//获取将返回的文档的迭代器
DocIterator iterator=docs.iterator();
//迭代所有文档并计算出现次数
对于(int i=0;i
现在,我找到了一个方法,可以迭代将由返回的所有文档,也就是说,如果查询找到1300个文档,而我只返回20个,那么现在我将只使用此方法迭代20个文档。我有可能得到全套文件(1300份)?有可能做到这一点。您使用的文档列表仅包含从“开始”开始的“行”文档。如果您想迭代所有“numFound”文档,请使用DocSet via
rb.getResults().docSet
为了理解这个机制-我已经尝试过了,但是我得到了一个nullpointer异常。你知道为什么在这个阶段它可能是空的吗?简单的解决方案(可能不是很好)。您能用param
rows=1300进行查询吗,这样您就可以在docListNo中获得所有文档了。我真的想弄清楚,为了便于您理解,@Johnny000 docSet不一定是定义的,除非您的搜索组件通过覆盖prepare(ResponseBuilder rb)请求它
方法和调用:rb.setNeedDocSet(true)方法内部的代码>。如果您的类执行此操作,那么QueryComponent将定义并填充docSet,并且假定您的搜索组件在QueryComponent之后被调用,则该docSet对您的搜索组件可用。