簡體   English   中英

Solr SearchComponent獲取所有文檔

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM