[英]Solr SearchComponent get all documents
I'm just writing a solr plugin (SearchComponent) and want to iterate over all documents that are found for the query. 我只是在编写一个solr插件(SearchComponent),并且要遍历为该查询找到的所有文档。 This is the part of my code in the process method:
这是处理方法中代码的一部分:
// 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());
}
}
For now I found a method where I can iterate over all documents that will be returned by ie if 1300 documents are found for the query and I only return 20, I will only iterate over 20 with this method for now. 现在,我找到了一种方法,可以在该方法上遍历将要返回的所有文档,即,如果为查询找到了1300个文档,而我仅返回20,则现在仅使用该方法遍历20多个。 I there a possibility to get the full set of documents (1300)?
我有可能获得全套文件(1300)吗?
There is a possibility to do that. 有可能这样做。 You use DocList which contains only 'rows' docs starting from 'start'.
您使用的DocList仅包含从“ start”开始的“ rows”文档。 If you want to iterate over all 'numFound' docs - use DocSet via
如果要遍历所有“ numFound”文档-通过以下方式使用DocSet
rb.getResults().docSet
For understanding of this mechanism - http://wiki.apache.org/solr/FAQ#How_can_I_get_ALL_the_matching_documents_back.3F_..._How_can_I_return_an_unlimited_number_of_rows.3F 为了了解这种机制-http: //wiki.apache.org/solr/FAQ#How_can_I_get_ALL_the_matching_documents_back.3F_..._How_can_I_return_an_unlimited_number_of_rows.3F
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.