lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dipesh <dipshres...@gmail.com>
Subject Re: About counting term hits
Date Thu, 13 Nov 2008 02:26:42 GMT
yes its quite possible.
1.you need to create term which you need to search.
eg.
Term term = new Term("yourfield","yourword");

2. then create a TermDoc enum.
TermDocs provides an interface for enumerating <document, frequency> pairs
for a term.

TermDocs t = new
FilterIndexReader(IndexReader.open("youindex")).termDocs(term);

3.Iterate through each of the terms and count the occurrence.
int count = 0;
 while(td.next()){
                    count+=td.freq());
  }

Hope it helped,
Regards,
Dipesh

On Thu, Nov 13, 2008 at 4:30 AM, Fco. Mario Barcala Rodríguez <
lbarcala@freeresearch.org> wrote:

> Hello:
>
> I am new to LUCENE and I am testing some issues about it. I can retrieve
> the number of documents which satisfies a query, but I don't find how to
> obtain the number of terms which match it.
>
> For example, if I search for the word "house", I want to obtain the
> number of times the word occurs (not the number of documents).
>
> Is it possible to do it in LUCENE?
>
> Thanks in advance,
>
>  Mario Barcala
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>


-- 
----------------------------------------
"Help Ever Hurt Never"- Baba
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message