You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Bertrand VENZAL <be...@cirso.fr> on 2005/01/13 11:03:33 UTC

IndexSearcher and number of occurence


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 ...

Tchõ
Bertrand



---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org


Re: IndexSearcher and number of occurence

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
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 = IndexReader.open(directory);

     ...
     // 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.

	Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org


Re: IndexSearcher and number of occurence

Posted by Morus Walter <mo...@tanto.de>.
Bertrand VENZAL writes:
> 
> 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.
> 
The use of a searcher does not prevent the use of a reader (in fact
the searcher relys on a reader).
So I'd use the searcher to find the document and a reader to get the
frequency using IndexReader.termDocs.
Depending on how many frequencies your interested in, the term vector
support might be of interest.

HTH
	Morus

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org