From java-user-return-39552-apmail-lucene-java-user-archive=lucene.apache.org@lucene.apache.org Tue Apr 07 17:48:00 2009 Return-Path: Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: (qmail 7286 invoked from network); 7 Apr 2009 17:48:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 7 Apr 2009 17:48:00 -0000 Received: (qmail 34264 invoked by uid 500); 7 Apr 2009 17:47:58 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 34205 invoked by uid 500); 7 Apr 2009 17:47:58 -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 34195 invoked by uid 99); 7 Apr 2009 17:47:58 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Apr 2009 17:47:58 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=HTML_MESSAGE X-Spam-Check-By: apache.org Received-SPF: unknown (nike.apache.org: error in processing during lookup of pjaol@pjaol.com) Received: from [74.125.46.29] (HELO yw-out-2324.google.com) (74.125.46.29) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Apr 2009 17:47:50 +0000 Received: by yw-out-2324.google.com with SMTP id 9so1592497ywe.5 for ; Tue, 07 Apr 2009 10:47:27 -0700 (PDT) MIME-Version: 1.0 Received: by 10.150.148.1 with SMTP id v1mr766370ybd.78.1239126447676; Tue, 07 Apr 2009 10:47:27 -0700 (PDT) In-Reply-To: <499888440904070601h4ce0f894ve2b35d6ae5f81826@mail.gmail.com> References: <499888440904070601h4ce0f894ve2b35d6ae5f81826@mail.gmail.com> Date: Tue, 7 Apr 2009 13:47:27 -0400 Message-ID: <1e33aedb0904071047u5fd0815dyc8d8cb95da8b6f27@mail.gmail.com> Subject: Re: How to customize score according to field value? From: "patrick o'leary" To: java-user@lucene.apache.org Content-Type: multipart/alternative; boundary=000e0cd4d7a0bede6c0466fa9b78 X-Virus-Checked: Checked by ClamAV on apache.org --000e0cd4d7a0bede6c0466fa9b78 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit You might want to play with both boosting and multiple sorting. You might want to look at something like Solr's boost queries or boost functions http://wiki.apache.org/solr/DisMaxRequestHandler#head-6862070cf279d9a09bdab971309135c7aea22fb3 Or if you want to go down the path of a custom score, most folks override the customScore method of CustomScoreQuery *//create a term query to search against all documents* Query tq = *new* TermQuery(*new* Term(*"metafile"*, *"doc"*)); FieldScoreQuery fsQuery = *new* FieldScoreQuery(*"geo_distance"*, Type.FLOAT); CustomScoreQuery customScore = *new* CustomScoreQuery(tq,fsQuery){ @Override *public* *float* customScore(*int* doc, *float* subQueryScore, *float* valSrcScore){ ..... return myFunkyScore; } } You can see a quick version in http://svn.apache.org/viewvc/lucene/java/trunk/contrib/spatial/src/test/org/apache/lucene/spatial/tier/TestCartesian.java?revision=762801&view=markup HTH P On Tue, Apr 7, 2009 at 9:01 AM, Tim Williams wrote: > On Tue, Apr 7, 2009 at 3:08 AM, Jinming Zhang > wrote: > > Hi, > > > > I have the following situation which needs to customize the final score > > according to field value. > > > > Suppose there are two docs in my query result, and they are ordered by > > default score sort: > > > > doc1(field1:bookA, field2:2000-01-01) -- score:0.80 > > doc2(field1:bookB, filed2:2009-01-01) -- score:0.70 > > > > I want "doc2" to have a higher score since it's publishing date is more > > recent, while "doc1" to have a lower score: > > > > doc2(field1:bookB, filed2:2009-01-01) -- score:0.77 > > doc1(field1:bookA, field2:2000-01-01) -- score:0.73 > > > > I found this scenario is different from doc.setBoost() and > field.setBoost(). > > Is there any way to impact the score calculated for "doc1" & "doc2" > > according to the value of "field2"? > > > > Thank you in advance! > > If you have access to the MEAP for Lucine In Action 2nd Edition, it > demonstrates using a CustomScoreQuery[1] for to boost a docs score > based on recency. > > --tim > > [1] - > http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/search/function/CustomScoreQuery.html > > --------------------------------------------------------------------- > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org > For additional commands, e-mail: java-user-help@lucene.apache.org > > --000e0cd4d7a0bede6c0466fa9b78--