3

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?

Thangnv
  • 805
  • 3
  • 11
  • 22

2 Answers2

1

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.

femtoRgon
  • 32,893
  • 7
  • 60
  • 87
0

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..

Community
  • 1
  • 1
Praba
  • 1,373
  • 10
  • 30