Lucene: termFreqVector always null?

for any document, the term FreqVector is always zero. I am sure that the documents are in the collection and the field exists. So where is the problem?

for (int i = 0; i <reader.numDocs (); i ++) {
TermFreqVector tfv = reader.getTermFreqVector (i, "tags");

thanks

+6
source share
1 answer

Are you sure you are indexing your fields with Field.TermVector.YES ? Here is 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); } 
+6
source

Source: https://habr.com/ru/post/886373/


All Articles