From lucene-user-return-10606-apmail-jakarta-lucene-user-archive=jakarta.apache.org@jakarta.apache.org Thu Oct 07 19:31:59 2004 Return-Path: Delivered-To: apmail-jakarta-lucene-user-archive@www.apache.org Received: (qmail 97060 invoked from network); 7 Oct 2004 19:31:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 7 Oct 2004 19:31:58 -0000 Received: (qmail 75825 invoked by uid 500); 7 Oct 2004 19:31:50 -0000 Delivered-To: apmail-jakarta-lucene-user-archive@jakarta.apache.org Received: (qmail 75778 invoked by uid 500); 7 Oct 2004 19:31: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 75765 invoked by uid 99); 7 Oct 2004 19:31:50 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from [210.86.15.145] (HELO mta202-rme.xtra.co.nz) (210.86.15.145) by apache.org (qpsmtpd/0.28) with ESMTP; Thu, 07 Oct 2004 12:31:48 -0700 Received: from mta1-rme.xtra.co.nz ([210.86.15.142]) by mta202-rme.xtra.co.nz with ESMTP id <20041007193145.FBRM15448.mta202-rme.xtra.co.nz@mta1-rme.xtra.co.nz> for ; Fri, 8 Oct 2004 08:31:45 +1300 Received: from bk20028v058jmd ([210.54.79.5]) by mta1-rme.xtra.co.nz with SMTP id <20041007193144.HVCG56.mta1-rme.xtra.co.nz@bk20028v058jmd> for ; Fri, 8 Oct 2004 08:31:44 +1300 From: "Fred Yu" To: "Lucene Users List" Subject: RE: Search Lucene documents returns 0 hits Date: Fri, 8 Oct 2004 08:27:02 +1300 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) In-Reply-To: X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Thanks Lars, thanks heaps! -----Original Message----- From: Lars Klevan [mailto:lklevan@DigitalRiver.com] Sent: Friday, October 08, 2004 3:30 AM To: Lucene Users List Subject: RE: Search Lucene documents returns 0 hits Use BooleanQuery to combine multiple Queries: BooleanQuery query = new BooleanQuery(); query.add(new TermQuery(new Term("type", "stockSingle")), true, false); query.add(new TermQuery(new Term("seqNo", "1000")), true, false); ... -----Original Message----- From: Fred Yu [mailto:fred.yu@xtra.co.nz] Sent: Wednesday, October 06, 2004 5:36 PM To: Lucene Users List Subject: RE: Search Lucene documents returns 0 hits Hi Lars Thanks for that! That solved my problem. By the way, I need build a QueryFilter using MultiTermQuery. How do I create a MultiTermQuery object that contains three terms, e.g. new Term("type", "stockSingle"); new Term("code", "1234"); new Term("seqNo", "1000"); Thanks Fred -----Original Message----- From: Lars Klevan [mailto:lklevan@DigitalRiver.com] Sent: Thursday, October 07, 2004 9:59 AM To: Lucene Users List Subject: RE: Search Lucene documents returns 0 hits If you're indexing with a Keyword field you need to use a TermQuery. QueryParser will only work for Text fields. The reason for this is that both the Text field and the QueryParser use the Analyzer to chop up the input into searchable chunks. Depending on the Analyzer this includes converting to lower-case, stripping trailing "s" and "ing" and removing stopwords like "the" and "and". The TermQuery and Keyword field both treat the input exactly as is. -Lars -----Original Message----- From: Fred Yu [mailto:fred.yu@xtra.co.nz] Sent: Wednesday, October 06, 2004 3:25 PM To: lucene-user@jakarta.apache.org Subject: Search Lucene documents returns 0 hits Hi Does anyone know why Lucene returns 0 hits when there are in fact three matches? The attached are two java class that repeat the problem. In the example, I created a Keyword field "type" for each document added. Lucene can correctly find the documents if I use "Text" field instead of "Keyword" field. Thanks in advance Fred package test; import java.io.IOException; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; public class IndexItems { public static void main(String[] args) throws IOException { try { IndexWriter writer = new IndexWriter("/test/index", new StandardAnalyzer(), true); indexDocs(writer); writer.optimize(); writer.close(); System.out.println("index finished."); } catch (IOException e) { System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage()); } } private static void indexDocs(IndexWriter writer) throws IOException { Document document=new Document(); document.add(Field.Keyword("type", "stockSingle")); document.add(Field.Text("desc", "test single 1")); writer.addDocument(document); document=new Document(); document.add(Field.Keyword("type", "stockSingle")); document.add(Field.Text("desc", "test single 2")); writer.addDocument(document); document=new Document(); document.add(Field.Keyword("type", "stockItem")); document.add(Field.Text("desc", "test single 3")); writer.addDocument(document); } } package test; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.search.Searcher; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.QueryFilter; import org.apache.lucene.search.Hits; import org.apache.lucene.queryParser.QueryParser; public class SearchItems { public static void main(String[] args) { try { Searcher searcher = new IndexSearcher("/test/index"); QueryParser qp=new QueryParser("type", new StandardAnalyzer()); Query query=qp.parse("type:stockSingle"); Hits hits = searcher.search(query); System.out.println("search found: "+hits.length() + " total matching documents"); searcher.close(); } catch (Exception e) { System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage()); } } } --------------------------------------------------------------------- To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: lucene-user-help@jakarta.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: lucene-user-help@jakarta.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: lucene-user-help@jakarta.apache.org