Return-Path: X-Original-To: apmail-lucene-java-user-archive@www.apache.org Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5A63DCD78 for ; Thu, 17 May 2012 08:30:33 +0000 (UTC) Received: (qmail 18602 invoked by uid 500); 17 May 2012 08:30:31 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 18374 invoked by uid 500); 17 May 2012 08:30:30 -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 18341 invoked by uid 99); 17 May 2012 08:30:29 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 May 2012 08:30:29 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of ian.lea@gmail.com designates 209.85.213.176 as permitted sender) Received: from [209.85.213.176] (HELO mail-yx0-f176.google.com) (209.85.213.176) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 May 2012 08:30:23 +0000 Received: by yenm14 with SMTP id m14so1982494yen.35 for ; Thu, 17 May 2012 01:30:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=SB3QCnr+ECnzN/itLXURQp7M+YEhzIEVM5ZCMSQC2wA=; b=WW0q/ZIFFYl8Jm9+EQEUqrQ2EwhPr5jI69iTE8OXDdolLxKAJd8wimK/EupGLPcOhK UBtt8y47t5M6mzyJmY0/ZFNzUwM4i0h6RlyTyw9kIrMC1hbyerJ5qsf3Wze6RsmU/MHl y+IJPymbM2pIgf3nV/gZtgjxF3dbaLm+QyQFhV2Ve9zO6+TzgbX1c+cWh9dSo9KmpZxR DPJwvNsRHmhHWEOj74MQyZlWp+a3HX6woo+J5uFh/DNxG4wlpmLTigBTTbcLjcB/qdWV 7nss7MVj0Q6YPyOPD9RJuE1KimdvTcUj9a4v8iltuNXJX/mY6stA1O9QP+CReX4HBS5E MjOQ== Received: by 10.43.133.135 with SMTP id hy7mr3694439icc.53.1337243402224; Thu, 17 May 2012 01:30:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.64.102.197 with HTTP; Thu, 17 May 2012 01:29:42 -0700 (PDT) In-Reply-To: References: From: Ian Lea Date: Thu, 17 May 2012 09:29:42 +0100 Message-ID: Subject: Re: Optional Terms To: java-user@lucene.apache.org Content-Type: text/plain; charset=ISO-8859-1 > Document doc3 = new Document(); > doc2.add(new Field("searchText", "LMN Takeaway", Field.Store.YES, doc2 != doc3. Boosting by number of occurrences tends to happen automatically. See IndexSearcher.explain() as I think someone already suggested. See also javadocs for org.apache.lucene.search.Similarity. You can plug in your own implementation if you want to tweak the scoring. -- Ian. On Wed, May 16, 2012 at 10:06 PM, Meeraj Kunnumpurath wrote: > Hi, > > I have the following documents > > Document doc1 = new Document(); > doc1.add(new Field("searchText", "ABC Takeaway fred@company.com > fred@company.com", Field.Store.YES, Field.Index.ANALYZED)); > Document doc2 = new Document(); > doc2.add(new Field("searchText", "XYZ Takeaway fred@company.com", > Field.Store.YES, Field.Index.ANALYZED)); > Document doc3 = new Document(); > doc2.add(new Field("searchText", "LMN Takeaway", Field.Store.YES, > Field.Index.ANALYZED)); > > My query is > > Query q = new QueryParser(Version.LUCENE_35, "searchText", > analyzer).parse("+Takeaway fred@company.com^100"); > > This returns only doc1 and doc2. How do I need to modify the query, so that > the first term (Takeaway) is mandatory and the second one (fred@company.com) > is optional? Also, I would like to boost those documents based on the > number of occurrences of the second term. > > Regards > Meeraj --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org For additional commands, e-mail: java-user-help@lucene.apache.org