lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rebecca Watson <>
Subject Re: Problem fetching number of occurrences
Date Wed, 02 Jun 2010 05:56:50 GMT

when you are indexing, use termvectors
set this in the Field object constructor when you create your Field objects
at index time.

i've never done it but i'm pretty sure these can be retrieved at
search time using one of the
IndexReader.getTermFreqVector methods.

lucene in action has a really good section on using termfreqvectors:

if you want the positional info too e.g. the two positions of the
"question" word in your
example then have a look at the
class -- in the getSpans method -- it grabs the terms + positions
using the IndexReader
as well: reader.termPositions(term)

hope that helps,

bec :)

On 2 June 2010 04:53, Sirish Vadala <> wrote:
> Hello All:
> Can any one suggest me the best way to get the no. of occurrences of each
> word per document in Lucene?
> Eg: Let the indexed text be:
> If you are posting a question, please try search first. Your question may
> have already been answered.
> Now if I search for the word 'question', then I would like to get this
> document along with the number of occurrences of question in the document,
> in the above case it would be 2.
> Any hint would be appreciated.
> Thanks.
> --
> View this message in context:
> Sent from the Lucene - Java Users mailing list archive at
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message