Return-Path: Delivered-To: apmail-jakarta-lucene-user-archive@www.apache.org Received: (qmail 43548 invoked from network); 31 Dec 2004 13:39:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 31 Dec 2004 13:39:10 -0000 Received: (qmail 6559 invoked by uid 500); 31 Dec 2004 13:38:51 -0000 Delivered-To: apmail-jakarta-lucene-user-archive@jakarta.apache.org Received: (qmail 6516 invoked by uid 500); 31 Dec 2004 13:38:50 -0000 Mailing-List: contact lucene-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Lucene Users List" Reply-To: "Lucene Users List" Delivered-To: mailing list lucene-user@jakarta.apache.org Received: (qmail 6448 invoked by uid 99); 31 Dec 2004 13:38:50 -0000 X-ASF-Spam-Status: No, hits=1.0 required=10.0 tests=HTML_20_30,HTML_MESSAGE,HTML_TITLE_EMPTY,PLING_PLING X-Spam-Check-By: apache.org Received-SPF: neutral (hermes.apache.org: local policy) Received: from p15112568.pureserver.info (HELO p15112568.pureserver.info) (217.160.91.29) by apache.org (qpsmtpd/0.28) with ESMTP; Fri, 31 Dec 2004 05:38:47 -0800 Received: from [192.168.10.103] (ppp-82-135-9-180.mnet-online.de [82.135.9.180]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by p15112568.pureserver.info (Postfix) with ESMTP id 5D20A14010F for ; Fri, 31 Dec 2004 14:38:43 +0100 (CET) Message-ID: <41D55658.2010105@intrafind.de> Date: Fri, 31 Dec 2004 14:38:32 +0100 From: Bernhard Messer Organization: IntraFind Software AG User-Agent: Mozilla Thunderbird 0.8 (X11/20040913) X-Accept-Language: de-DE, de, en-us, en MIME-Version: 1.0 To: Lucene Users List Subject: Re: Search not working properly. Bug !!!!!! References: <20041230164347.31562.qmail@web42001.mail.yahoo.com> In-Reply-To: Content-Type: multipart/alternative; boundary="------------090006040409060201010201" X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N --------------090006040409060201010201 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit your code is not correct. You're opening the Searcher before inserting the documents into the index. Place the code where you are creating the IndexSearcher after IndexWriters optimize() and it will work. Bernhard Searcher objIndexSearcher = new IndexSearcher("index"); >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" >To: "Lucene Users List" >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 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 > > > --------------090006040409060201010201--