Lucene 4.0中的术语向量频率 [英] Term Vector Frequency in Lucene 4.0
本文介绍了Lucene 4.0中的术语向量频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从Lucene 3.6升级到Lucene 4.0-beta.在Lucene 3.x中,IndexReader
包含方法IndexReader.getTermFreqVectors()
,我可以使用该方法提取给定文档和字段中每个术语的频率.
I'm upgrading from Lucene 3.6 to Lucene 4.0-beta. In Lucene 3.x, the IndexReader
contains a method IndexReader.getTermFreqVectors()
, which I can use to extract the frequency of each term in a given document and field.
此方法现在由IndexReader.getTermVectors()
代替,该方法返回Terms
.如何利用这种(或可能的其他方法)提取文档和字段中的术语频率?
This method is now replaced by IndexReader.getTermVectors()
, which returns Terms
. How can I make use of this (or probably other methods) to extract the term frequency in a document and a field?
推荐答案
也许这会帮助您:
// get terms vectors for one document and one field
Terms terms = reader.getTermVector(docID, "fieldName");
if (terms != null && terms.size() > 0) {
// access the terms for this field
TermsEnum termsEnum = terms.iterator(null);
BytesRef term = null;
// explore the terms for this field
while ((term = termsEnum.next()) != null) {
// enumerate through documents, in this case only one
DocsEnum docsEnum = termsEnum.docs(null, null);
int docIdEnum;
while ((docIdEnum = docsEnum.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
// get the term frequency in the document
System.out.println(term.utf8ToString()+ " " + docIdEnum + " " + docsEnum.freq());
}
}
}
这篇关于Lucene 4.0中的术语向量频率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文