Frank
Frank

Reputation: 4417

Find list of terms indexed by Lucene

Is it possible to extract the list of all the terms in a Lucene index as a list of strings? I couldn't find that functionality in the doc. Thanks!

Upvotes: 10

Views: 11369

Answers (2)

Rob Audenaerde
Rob Audenaerde

Reputation: 20099

In Lucene 4 (and 5):

 Terms terms = SlowCompositeReaderWrapper.wrap(directoryReader).terms("field"); 

Edit:

This seems to be the 'correct' way now (Lucene 6 and up):

LuceneDictionary ld = new LuceneDictionary( indexReader, "field" );
BytesRefIterator iterator = ld.getWordsIterator();
BytesRef byteRef = null;
while ( ( byteRef = iterator.next() ) != null )
{
    String term = byteRef.utf8ToString();
}

Upvotes: 17

miku
miku

Reputation: 188164

Lucene 3:

Upvotes: 12

Related Questions