如何通过lucene索引和搜索得到顶级单词?

时间:2013-10-03 16:55:04

标签: java search lucene indexing

我使用lucene库来创建索引和搜索。但是现在我希望在我的文本中出现的大部分单词都能得到前30个单词。我该怎么办?

2 个答案:

答案 0 :(得分:1)

如果您使用的是Lucene 4.0或更高版本,则可以使用HighFreqTerms类,例如:

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
}

从每个TermStats对象中,您可以获取频率,字段名称和文本。

答案 1 :(得分:0)

在SO中快速搜索得到了我:Get highest frequency terms from Lucene index

这对你有用吗?听起来像是完全相同的问题..