lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mohamed Ebrahim Faisal" <ebrahim_faisal...@hotmail.com>
Subject Search not working properly. Bug !!!!!!
Date Thu, 30 Dec 2004 16:36:46 GMT
Hi all

I have written a simple program to test Indexing & Search. After indexing couple of documents,
I Searched for the same, but i didn't get Successfull matches. I don't know whether it is
a bug in Lucene or in the code. I have enclosed the code for your review.

But when i used Lucene for bigger applications ( index contains larger documents ), search
worked amazingly.


Following is the code which didn't work properly

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;

import org.apache.lucene.search.Searcher;

public class testLucene
{
 private static final String[] strSTOP_WORDS =
        {
   "and",
   "are",
   "was",
   "will",
   "with" };
 private void test() throws Exception
 {
  Analyzer objAnalyzer = new StandardAnalyzer();
  IndexWriter index = new IndexWriter("index",objAnalyzer, true );
  Searcher objIndexSearcher = new IndexSearcher("index");
        

  Document d = new Document();
 
  d.add( Field.Text("name","Ebrahim Faisal"));
  d.add( Field.Text("address","New York"));
  d.add( Field.Text("designation","Software Engineer"));
  d.add( Field.Text("xyz","123 IndexWriter index"));

  index.addDocument( d );

  d = new Document();

  d.add( Field.Text("name","John Smith"));
  d.add( Field.Text("address","India"));
  d.add( Field.Text("designation","Sr. Software Engineer"));
  d.add( Field.Text("xyz","456 StandardAnalyzer true"));

  index.addDocument( d );

  

  index.optimize();
  index.close();
  
  
  Query objQuery = null;

  objQuery = QueryParser.parse("Engineer", "name"
                , objAnalyzer);

  
  Hits objHits = objIndexSearcher.search(objQuery);

  
  for (int nStart = 0; nStart < objHits.length(); nStart++) 
  {
   d = objHits.doc(nStart);
   System.out.println(" address "+d.get("address"));
  }
  
 }
 public static void main(String[] args) throws Exception
 {
  new testLucene().test();
 }
}

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