for any document, the termFreqVector is always null. I'm sure the documents are in the collection and the field exist. So where is the problem ?
for (int i = 0; i < reader.numDocs(); i++){
TermFreqVector tfv = reader.getTermFreqVector(i, "tags");
thanks
Are you sure you're indexing with your fields with Field.TermVector.YES
? Here's a working example:
Directory directory = new RAMDirectory();
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30);
MaxFieldLength mlf = MaxFieldLength.UNLIMITED;
IndexWriter writer = new IndexWriter(directory, analyzer, true, mlf);
Document doc = new Document();
doc.add(new Field("tags", "foo bar", Field.Store.NO,
Field.Index.ANALYZED, Field.TermVector.YES));
writer.addDocument(doc);
writer.close();
IndexReader reader = IndexReader.open(directory);
for (int i = 0; i < reader.numDocs(); i++) {
TermFreqVector tfv = reader.getTermFreqVector(i, "tags");
System.out.println(tfv);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With