lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <>
Subject Re: IndexSearcher and number of occurence
Date Thu, 13 Jan 2005 10:28:12 GMT

On Jan 13, 2005, at 5:03 AM, Bertrand VENZAL wrote:

> Hi all,
> Im quite new in this mailing list. I ve many difficulties to find the
> number of a word (occurence) in a document, I need to use indexSearcher
> because of the query but the score returning is not wot i m looking 
> for.
> I found in the mailing List the class TermDoc but it seems to work only
> with indexReader.
> If anyone can give a hand of this one, I will appreciate ...

Perhaps this technique is what you're looking for.... set the field(s) 
you're interested in capturing frequency on to be vectored.  You'll see 
that flag as additional overloaded methods on the Field.  You'll still 
need to use an IndexReader, but that is no problem.  Construct an 
IndexReader and use it to construct the IndexSearcher that you'll also 
use.  Here's some snippets of code:

	// During indexing, "subject" field was added like this:
     doc.add(Field.UnStored("subject", subject, true));

... // now during searching...

     IndexReader reader =;

     // from your Hits, get the document id
     int id = hits.doc(i);

     TermFreqVector vector =
         reader.getTermFreqVector(id, "subject");

Now read up on the TermFreqVector API to get at the frequency of a 
specific term.


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

View raw message