简体   繁体   中英

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. 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. I there a possibility to get the full set of documents (1300)?

There is a possibility to do that. You use DocList which contains only 'rows' docs starting from 'start'. If you want to iterate over all 'numFound' docs - use DocSet via

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM