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 Re: Search not working properly. Bug !!!!!!
Date Fri, 31 Dec 2004 04:25:20 GMT
Hi all

I made a mistake when I copied and pasted the code.
The actual code is as follows:

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("John", "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();
 }
}


----- Original Message -----
From: "mahaveer jain" <jainmahaveer23@yahoo.com>
To: "Lucene Users List" <lucene-user@jakarta.apache.org>
Sent: Thursday, December 30, 2004 10:13 PM
Subject: Re: Search not working properly. Bug !!!!!!


> try this
>
> objQuery = QueryParser.parse("John", "name" , objAnalyzer);
> or
> objQuery = QueryParser.parse("Engineer", "designation", objAnalyzer);
>
> I should work.
>
> The second parameter is the column name you pass. So if you are search for
"name", it will look for only name column.
>
> Hope this help you
>
> Mahaveer
>
> 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();
> }
> }
>
>
> ---------------------------------
> Do you Yahoo!?
>  Jazz up your holiday email with celebrity designs. Learn more.

---------------------------------------------------------------------
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