lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Snare <mikesn...@gmail.com>
Subject Re: Search not working properly. Bug !!!!!!
Date Thu, 30 Dec 2004 16:45:13 GMT
You appear to be searching for the word "Engineer" in the "name"
field.  Shouldn't this query be directed at the "designation" field? 
The only terms in the name field would be "Ebrahim", "Faisal", "John",
and "Smith", wouldn't they?


On Thu, 30 Dec 2004 22:06:46 +0530, Mohamed Ebrahim Faisal
<ebrahim_faisal123@hotmail.com> wrote:
> 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();
>  }
> }
> 
>

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


Mime
View raw message