Return-Path: Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: (qmail 1259 invoked from network); 10 Jul 2005 10:09:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 10 Jul 2005 10:09:21 -0000 Received: (qmail 31682 invoked by uid 500); 10 Jul 2005 10:09:17 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 31657 invoked by uid 500); 10 Jul 2005 10:09:16 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 31643 invoked by uid 99); 10 Jul 2005 10:09:16 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 10 Jul 2005 03:09:16 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [69.55.225.129] (HELO ehatchersolutions.com) (69.55.225.129) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 10 Jul 2005 03:09:13 -0700 Received: by ehatchersolutions.com (Postfix, from userid 504) id E6FAD13E2007; Sun, 10 Jul 2005 06:09:05 -0400 (EDT) Received: from [172.16.1.101] (va-71-48-129-227.dhcp.sprint-hsd.net [71.48.129.227]) by ehatchersolutions.com (Postfix) with ESMTP id 2859113E2005 for ; Sun, 10 Jul 2005 06:08:36 -0400 (EDT) Mime-Version: 1.0 (Apple Message framework v730) In-Reply-To: <20050710044035.51924.qmail@web31210.mail.mud.yahoo.com> References: <20050710044035.51924.qmail@web31210.mail.mud.yahoo.com> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <5DB8BB95-C3F2-44A4-90EA-BF32E112D9DC@ehatchersolutions.com> Content-Transfer-Encoding: 7bit From: Erik Hatcher Subject: Re: Query -- how to write Date: Sun, 10 Jul 2005 06:08:38 -0400 To: java-user@lucene.apache.org X-Mailer: Apple Mail (2.730) X-Spam-Checker-Version: SpamAssassin 3.0.1 (2004-10-22) on javelina X-Spam-Level: X-Virus-Checked: Checked by ClamAV on apache.org X-Old-Spam-Status: No, score=-5.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.0.1 X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N On Jul 10, 2005, at 12:40 AM, bib_lucene bib wrote: > Hi All > > I am indexing a document like this... > > Document doc = new Document(); > doc.add(Field.Text("contents", new FileReader(f))); > doc.add(Field.Text("filename",f.getCanonicalPath())); > Iterator it = fields.keySet().iterator(); > String element = ""; > while (it.hasNext()) { > element = (String)it.next(); > doc.add(Field.Text(element,(String)fields.get > (element))); // also tried field.keyword > } > writer.addDocument(doc); > writer.optimize(); > writer.close(); > > So the lucene doc has the text of the uploaded doc and also some > params like author, date, etc. > > When I write my search > > String queryStr = request.getParameter("query"); > > File indexDir = new File("c:/luceneindex"); > > Directory fsDir = FSDirectory.getDirectory(indexDir,false); > > IndexSearcher is = new IndexSearcher(fsDir); > > Query query = QueryParser.parse(queryStr,"contents", new > StandardAnalyzer()); > > Hits hits = is.search(query); > > Not surprisingly I get a match only if there is a word in the > contents of the document. > > Question: If my query should be able to search not only document > contents but also the other data added such as author how do I do > that. There are two common options here: - MultiFieldQueryParser - Use an aggregate field for all searchable text I personally prefer the aggregate field approach as it makes the queries much simpler under the covers. Erik --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org For additional commands, e-mail: java-user-help@lucene.apache.org