lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erick Erickson" <erickerick...@gmail.com>
Subject Re: Searching for instances within a document
Date Wed, 09 Jul 2008 14:00:52 GMT
I know this has been discussed before, so if you search the
archive you might find an answer more quickly. I don't
remember what the resolution was, so I can't help there.

Best
Erick

On Wed, Jul 9, 2008 at 9:49 AM, jnance <nancejd@ornl.gov> wrote:

>
> Hi,
>
> I am indexing lots of text files and need to see how many times a certain
> word comes up in each text file. Right now I have this constructor for
> "search":
>
>  static void search(Searcher searcher, String queryString) throws
> ParseException, IOException {
>                 QueryParser parser = new QueryParser("content", new
> StandardAnalyzer());
>                 Query query = parser.parse(queryString);
>                 Hits hits = searcher.search(query);
>
>                 int hitCount = hits.length();
>                 if (hitCount == 0) {
>                         System.out.println("0 documents contain the word
> \"" + queryString +
> ".\"");
>                 }
>                 else {
>                         System.out.println(hitCount + " documents contain
> the word \"" +
> queryString + ".\"");
>                 }
>         }
>
> This tells me how many documents contain the word I'm looking for... but
> how
> do I get it to tell me how many times the word occurs within that document?
>
> Thanks,
>
> James
> --
> View this message in context:
> http://www.nabble.com/Searching-for-instances-within-a-document-tp18362075p18362075.html
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message