Thangnv
Thangnv

Reputation: 815

How to get top words by lucene index and search?

I used lucene library to create index and search. But now I want to get top 30 words are most of the words appearing in my texts. What can I do?

Upvotes: 3

Views: 2060

Answers (2)

femtoRgon
femtoRgon

Reputation: 33341

If you are using Lucene 4.0 or later, you can use the HighFreqTerms class, such as:

TermStats[] commonTerms = HighFreqTerms.getHighFreqTerms(reader, 30, "mytextfield");
for (TermStats commonTerm : commonTerms) {
    System.out.println(commonTerm.termtext.utf8ToString()); //Or whatever you need to do with it
}

From each TermStats object, you can get the frequencies, field name, and text.

Upvotes: 1

Praba
Praba

Reputation: 1381

A quick search in SO got me this: Get highest frequency terms from Lucene index

Would this work for you? sounded like the exact same question..

Upvotes: 0

Related Questions