Hi Adrien, Thank you very much for the reply. I have two other small question about this: 1) Is "final int freq = docsAndPositions.freq();" the same with "iterator.totalTermFreq()" ? In my tests it returns the same result and from the documentation it seems that the result should be the same.
2) How do I get the offsets for the term vector? I have tried to iterate over the docsAndPositions but I get the following exception: Exception in thread "main" java.lang.IllegalStateException: Position enum not started Thanks in advance, Andi > From: jpou...@gmail.com > Date: Tue, 2 Apr 2013 12:05:12 +0200 > Subject: Re: Term vector Lucene 4.2 > To: java-user@lucene.apache.org > > Hi Andi, > > Here is how you could retrieve positions from your document: > > Terms termVector = indexReader.getTermVector(docId, fieldName); > TermsEnum reuse = null; > TermsEnum iterator = termVector.iterator(reuse); > BytesRef ref = null; > DocsAndPositionsEnum docsAndPositions = null; > while ((ref = iterator.next()) != null) { > docsAndPositions = iterator.docsAndPositions(null, docsAndPositions); > // beware that docsAndPositions will be null if you didn't > index positions > if (docsAndPositions.nextDoc() != 0) { // you need to call > nextDoc() to have the enum positioned > throw new AssertionError(); > } > final int freq = docsAndPositions.freq(); // number of > occurrences of the term > for (int i = 0; i < freq; ++i) { > final int position = docsAndPositions.nextPosition(); > // 'position' is the i-th position of the current term in the > document > } > } > > I hope this helps. > > -- > Adrien > > --------------------------------------------------------------------- > To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org > For additional commands, e-mail: java-user-h...@lucene.apache.org >