lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "AJIT RAJWADE" <ajit.rajw...@veritas.com>
Subject Re: Finding number of occurrences of a given word in a document using LUCENE
Date Fri, 07 Jun 2002 06:05:00 GMT
I tried out the following code to find the number of occurrences of a word in a document using
Lucene. It doesnt work...can someone help me?


{
     IndexReader reader = IndexReader.open("index"); 
     Searcher searcher = new IndexSearcher("index");
     Analyzer analyzer = new StandardAnalyzer();
 
    BufferedReader in = new BufferedReader(new
     InputStreamReader(System.in));
 
    // CODE TO TAKE A LINE FROM THE USER
 
    Query query = QueryParser.parse(line, "contents", analyzer);
    Hits hits = searcher.search(query);
    Term term = new Term("body", line);   /* line is the actual text being searched */
    TermDocs help = reader.termDocs(term); 
 
  /* THIS LOOP IS NEVER ENTERED WHEN THE CODE IS EXECUTED!*/
     while (help.next() == true)
     {
         System.out.println ("\nFreq: " + help.freq());
     }
 
    int [] docs = new int [hits.length()];
    int [] frequency = new int [hits.length()];
    help.read (docs,frequency);
 
    // PRINT THE ARRAYS DOCS AND FREQUENCY. ALL VALUES ARE ZERO!
 }
 
    
 Can you help me please? The while loop is never entered and the array of document numbers
and word frequencies contains all zeroes. Why is this happening?


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