Term Vector Frequency in Lucene 4.0 - Stack Overflow
Perhaps will help you:
Terms terms = reader.getTermVector(docID, "fieldName"); //get terms vectors for one document and one field
if (terms != null && terms.size() > 0) {
TermsEnum termsEnum = terms.iterator(null); // access the terms for this field
BytesRef term = null;
while ((term = termsEnum.next()) != null) {// explore the terms for this field
DocsEnum docsEnum = termsEnum.docs(null, null); // enumerate through documents, in this case only one
int docIdEnum;
while ((docIdEnum = docsEnum.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
System.out.println(term.utf8ToString()+" "+docIdEnum+" "+docsEnum.freq()); //get the term frequency in the document
}
}
}
Read full article from Term Vector Frequency in Lucene 4.0 - Stack Overflow
No comments:
Post a Comment