Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all terms in index directory created by lucene 4.4.0

Tags:

java

lucene

I's using lucene 4.4 for index my docs, and now I want to get all terms by IndexReader. In older version I used:

IndexReader reader = new IndexReader.open(pathIndexDirectory);
TermEnum listTerm = reader.terms();

But in version 4.4 I can't do it. What can I do now ?

like image 690
Thangnv Avatar asked Oct 06 '13 11:10

Thangnv


1 Answers

So I'm using this way:

IndexReader reader = IndexReader.open(ramdir)
Fields fields = MultiFields.getFields(reader);
        for (String field : fields) {
            Terms terms = fields.terms(field);
            TermsEnum termsEnum = terms.iterator(null);
            int count = 0;
            while (termsEnum.next() != null) {
                count++;
            }
            System.out.println(count);
        }
like image 68
Thangnv Avatar answered Sep 24 '22 10:09

Thangnv