<< 金融危机下软件企业的机遇 | 首页 | JDBM纯Java数据库性能测试评估 >>

How to read all the data from an Lucene index?

How to read all the data from a Lucene index?

Document numbers start at 0. You will never get a document marked "deleted" from either IndexReader or IndexSearcher.


IndexReader reader = IndexReader.open(....);

for (int i = 0; i < reader.maxDoc(); i++) {
       if (reader.isDeleted(i)) {
               continue;
       }
       Document doc = reader.document(i);
       ...
}

Hint: if you have an unoptimized index with deleted documents, and you want to retrieve also the content of these deleted documents, call first IndexReader.undeleteAll().

Apache Lucene is a high-performance, full-featured text search engine library written entirely in Java. It is a technology suitable for nearly any application that requires full-text search, especially cross-platform.

Apache Lucene is an open source project available for free download. Please use the links on the left to access Lucene.

 

 

补充另一个方法:

 TermDocs td = IndexReader.termDocs(null);

然后迭代td

标签 : ,



发表评论 发送引用通报