用Lucene计算短语DF的最佳方法

用Lucene计算短语DF的最佳方法,lucene,information-retrieval,Lucene,Information Retrieval,如何使用Lucene(4.6)计算给定短语的文档频率 我找到了一种计算一个术语DF的方法。 对于短语(1-5个单词)有没有像这样优雅的东西 UPD:我所说的短语是指文档中必须出现的一系列术语。而且它们必须在文本中一个接一个地出现。Java代码: 看来PhraseQuery就是解决方案 for (termString <- splitted) { pq.add(new Term(IndexProperties.textField, termString)) } pq.setSlop(0

如何使用Lucene(4.6)计算给定短语的文档频率

我找到了一种计算一个术语DF的方法。
对于短语(1-5个单词)有没有像这样优雅的东西

UPD:我所说的短语是指文档中必须出现的一系列术语。而且它们必须在文本中一个接一个地出现。

Java代码:


看来PhraseQuery就是解决方案

for (termString <- splitted) {
  pq.add(new Term(IndexProperties.textField, termString))
}
pq.setSlop(0)

val collector = TopScoreDocCollector.create(5000, true)
searcher.search(pq, collector)

for(termString)我得到的结果中没有短语中的任何单词。你指的是哪一个分析器?应该是索引过程中使用的同一个分析器。例如,StandardAnalyzer。我不理解“我得到的结果中没有任何单词…”的意思。我的示例返回术语“你的”和“短语”,其中术语短语正好位于术语“您的”之后。
String phrase = "your phrase";
Query q = new Queryparser(Version.LUCENE_46, "field", analyzer).parse(phrase);
int df = new IndexSearher(reader).search(q, null).scoreDocs.length;
for (termString <- splitted) {
  pq.add(new Term(IndexProperties.textField, termString))
}
pq.setSlop(0)

val collector = TopScoreDocCollector.create(5000, true)
searcher.search(pq, collector)