是否可以迭代存储在Lucene Index中的文档?

Eug*_*ica 22 lucene lucene.net

我有一些文档存储在带有docId字段的Lucene索引中.我想将所有docId存储在索引中.还有一个问题.文件数量约为30万,所以我更愿意将这个文件放在500块大小的文件中.是否可以这样做?

baj*_*ife 47

IndexReader reader = // create IndexReader
for (int i=0; i<reader.maxDoc(); i++) {
    if (reader.isDeleted(i))
        continue;

    Document doc = reader.document(i);
    String docId = doc.get("docId");

    // do something with docId here...
}
Run Code Online (Sandbox Code Playgroud)

  • 如果缺少(reader.isDeleted(i)),该怎么办? (2认同)

bco*_*lan 17

Lucene 4

Bits liveDocs = MultiFields.getLiveDocs(reader);
for (int i=0; i<reader.maxDoc(); i++) {
    if (liveDocs != null && !liveDocs.get(i))
        continue;

    Document doc = reader.document(i);
}
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅此页面上的LUCENE-2600:https://lucene.apache.org/core/4_0_0/MIGRATE.html


Chu*_*Lyu 6

有一个名为的查询类MatchAllDocsQuery,我认为在这种情况下可以使用它:

Query query = new MatchAllDocsQuery();
TopDocs topDocs = getIndexSearcher.search(query, RESULT_LIMIT);
Run Code Online (Sandbox Code Playgroud)