You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Kelvin Tan <ke...@relevanz.com> on 2003/01/31 02:12:05 UTC

Re: [FAQ] Finding number of occurrences of a given word in a document

Yep. Here's some sample code for those who aren't sure how to use Term, 
TermDocs...

        IndexReader reader = IndexReader.open("c:/index");
        String value = "foobar";
        Term t = new Term(field, value);
        TermDocs termDocs = reader.termDocs(t);
        try
        {
            while (termDocs.next())
            {
                int docNumber = termDocs.doc();
                Document doc = reader.document(docNumber);
                System.out.println("Document:" + doc + " has " + 
termDocs.freq() + " occurences of " + value);
            }
        }
        finally
        {
            if (termDocs != null) termDocs.close();
        }

HTH

Regards,
Kelvin

--------
The book giving manifesto     - http://how.to/sharethisbook


On Thu, 30 Jan 2003 05:56:55 -0800 (PST), Otis Gospodnetic said:
>Would this be the correct answer?
>http://www.mail-archive.com/lucene-
>user@jakarta.apache.org/msg01738.html
>
>I haven't tested it...
>
>Otis
>
>--- Kelvin Tan <ke...@relevanz.com> wrote:
>>Maybe this is a good FAQ entry, under Searching?
>>
>>
>http://www.mail-archive.com/lucene-
>user@jakarta.apache.org/msg01735.html
>>
>>Regards, Kelvin
>>
>>--------
>>The book giving manifesto     - http://how.to/sharethisbook
>>
>>
>>
>>
>>--------------------------------------------------------------------
>>-
>>To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: lucene-dev-help@jakarta.apache.org
>>
>
>
>__________________________________________________ Do you Yahoo!?
>Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
>http://mailplus.yahoo.com
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: lucene-dev-help@jakarta.apache.org




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