Я просто пишу плагин 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, который содержит только "строки" docs, начиная с "start". Если вы хотите перебрать все документы '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