![](/img/trans.png)
[英]How can i make a SearchComponent Solr plugin distributed aware?
[英]Solr SearchComponent get all documents
我只是在编写一个solr插件(SearchComponent),并且要遍历为该查询找到的所有文档。 这是处理方法中代码的一部分:
// 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());
}
}
现在,我找到了一种方法,可以在该方法上遍历将要返回的所有文档,即,如果为查询找到了1300个文档,而我仅返回20,则现在仅使用该方法遍历20多个。 我有可能获得全套文件(1300)吗?
有可能这样做。 您使用的DocList仅包含从“ start”开始的“ rows”文档。 如果要遍历所有“ numFound”文档-通过以下方式使用DocSet
rb.getResults().docSet
为了了解这种机制-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.