lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gsing...@apache.org
Subject svn commit: r804178 - in /lucene/java/trunk/src: java/org/apache/lucene/search/ java/org/apache/lucene/search/payloads/ test/org/apache/lucene/search/payloads/
Date Fri, 14 Aug 2009 12:14:19 GMT
Author: gsingers
Date: Fri Aug 14 12:14:19 2009
New Revision: 804178

URL: http://svn.apache.org/viewvc?rev=804178&view=rev
Log:
LUCENE-1790: pass in position information for scoring

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/search/Similarity.java
    lucene/java/trunk/src/java/org/apache/lucene/search/payloads/AveragePayloadFunction.java
    lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingFunctionTermQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingNearQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/payloads/MaxPayloadFunction.java
    lucene/java/trunk/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java
    lucene/java/trunk/src/java/org/apache/lucene/search/payloads/PayloadFunction.java
    lucene/java/trunk/src/test/org/apache/lucene/search/payloads/BoostingFunctionTermQueryTest.java
    lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestBoostingNearQuery.java
    lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestBoostingTermQuery.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/Similarity.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/Similarity.java?rev=804178&r1=804177&r2=804178&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/Similarity.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/Similarity.java Fri Aug 14 12:14:19
2009
@@ -546,7 +546,7 @@
    * @param length The length in the array
    * @return An implementation dependent float to be used as a scoring factor
    *
-   * @deprecated See {@link #scorePayload(int, String, byte[], int, int)}
+   * @deprecated See {@link #scorePayload(int, String, int, int, byte[], int, int)}
    */
   //TODO: When removing this, set the default value below to return 1.
   public float scorePayload(String fieldName, byte [] payload, int offset, int length)
@@ -564,13 +564,15 @@
    *
    * @param docId The docId currently being scored.  If this value is {@link #NO_DOC_ID_PROVIDED},
then it should be assumed that the PayloadQuery implementation does not provide document information
    * @param fieldName The fieldName of the term this payload belongs to
+   * @param start The start position of the payload
+   * @param end The end position of the payload
    * @param payload The payload byte array to be scored
    * @param offset The offset into the payload array
    * @param length The length in the array
    * @return An implementation dependent float to be used as a scoring factor
    *
    */
-  public float scorePayload(int docId, String fieldName, byte [] payload, int offset, int
length)
+  public float scorePayload(int docId, String fieldName, int start, int end, byte [] payload,
int offset, int length)
   {
     //TODO: When removing the deprecated scorePayload above, set this to return 1
     return scorePayload(fieldName, payload, offset, length);

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/payloads/AveragePayloadFunction.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/payloads/AveragePayloadFunction.java?rev=804178&r1=804177&r2=804178&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/payloads/AveragePayloadFunction.java
(original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/payloads/AveragePayloadFunction.java
Fri Aug 14 12:14:19 2009
@@ -1,4 +1,6 @@
 package org.apache.lucene.search.payloads;
+
+import org.apache.lucene.index.Term;
 /**
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -25,7 +27,7 @@
  **/
 public class AveragePayloadFunction extends PayloadFunction{
 
-  public float currentScore(int docId, String field, int numPayloadsSeen, float currentScore,
float currentPayloadScore) {
+  public float currentScore(int docId, String field, int start, int end, int numPayloadsSeen,
float currentScore, float currentPayloadScore) {
     return currentPayloadScore + currentScore;
   }
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingFunctionTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingFunctionTermQuery.java?rev=804178&r1=804177&r2=804178&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingFunctionTermQuery.java
(original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingFunctionTermQuery.java
Fri Aug 14 12:14:19 2009
@@ -106,8 +106,8 @@
       protected void processPayload(Similarity similarity) throws IOException {
         if (positions.isPayloadAvailable()) {
           payload = positions.getPayload(payload, 0);
-          payloadScore = function.currentScore(doc, term.field(), payloadsSeen, payloadScore,
-                  similarity.scorePayload(doc, term.field(), payload, 0, positions.getPayloadLength()));
+          payloadScore = function.currentScore(doc, term.field(), spans.start(), spans.end(),
payloadsSeen, payloadScore,
+                  similarity.scorePayload(doc, term.field(), spans.start(), spans.end(),
payload, 0, positions.getPayloadLength()));
           payloadsSeen++;
 
         } else {

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingNearQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingNearQuery.java?rev=804178&r1=804177&r2=804178&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingNearQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/payloads/BoostingNearQuery.java Fri
Aug 14 12:14:19 2009
@@ -102,12 +102,12 @@
       for (int i = 0; i < subSpans.length; i++) {
         if (subSpans[i] instanceof NearSpansOrdered) {
           if (((NearSpansOrdered) subSpans[i]).isPayloadAvailable()) {
-            processPayloads(((NearSpansOrdered) subSpans[i]).getPayload());
+            processPayloads(((NearSpansOrdered) subSpans[i]).getPayload(), subSpans[i].start(),
subSpans[i].end());
           }
           getPayloads(((NearSpansOrdered) subSpans[i]).getSubSpans());
         } else if (subSpans[i] instanceof NearSpansUnordered) {
           if (((NearSpansUnordered) subSpans[i]).isPayloadAvailable()) {
-            processPayloads(((NearSpansUnordered) subSpans[i]).getPayload());
+            processPayloads(((NearSpansUnordered) subSpans[i]).getPayload(), subSpans[i].start(),
subSpans[i].end());
           }
           getPayloads(((NearSpansUnordered) subSpans[i]).getSubSpans());
         }
@@ -115,15 +115,19 @@
     }
 
     /**
-     * By default, sums the payloads, but can be overridden to do other things.
+     * By default, uses the {@link PayloadFunction} to score the payloads, but can be overridden
to do other things.
      *
      * @param payLoads The payloads
+     * @param start The start position of the span being scored
+     * @param end The end position of the span being scored
+     *
+     * @see {@link org.apache.lucene.search.spans.Spans}
      */
-    protected void processPayloads(Collection payLoads) {
+    protected void processPayloads(Collection payLoads, int start, int end) {
       for (Iterator iterator = payLoads.iterator(); iterator.hasNext();) {
         byte[] thePayload = (byte[]) iterator.next();
-        payloadScore = function.currentScore(doc, fieldName, payloadsSeen, payloadScore,
-                similarity.scorePayload(doc, fieldName, thePayload, 0, thePayload.length));
+        payloadScore = function.currentScore(doc, fieldName, start, end, payloadsSeen, payloadScore,
+                similarity.scorePayload(doc, fieldName, spans.start(), spans.end(), thePayload,
0, thePayload.length));
         ++payloadsSeen;
       }
     }

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/payloads/MaxPayloadFunction.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/payloads/MaxPayloadFunction.java?rev=804178&r1=804177&r2=804178&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/payloads/MaxPayloadFunction.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/payloads/MaxPayloadFunction.java Fri
Aug 14 12:14:19 2009
@@ -1,4 +1,6 @@
 package org.apache.lucene.search.payloads;
+
+import org.apache.lucene.index.Term;
 /**
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -24,7 +26,7 @@
  *
  **/
 public class MaxPayloadFunction extends PayloadFunction{
-  public float currentScore(int docId, String field, int numPayloadsSeen, float currentScore,
float currentPayloadScore) {
+  public float currentScore(int docId, String field, int start, int end, int numPayloadsSeen,
float currentScore, float currentPayloadScore) {
     return Math.max(currentPayloadScore, currentScore);
   }
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java?rev=804178&r1=804177&r2=804178&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/payloads/MinPayloadFunction.java Fri
Aug 14 12:14:19 2009
@@ -1,5 +1,7 @@
 package org.apache.lucene.search.payloads;
 
+import org.apache.lucene.index.Term;
+
 
 /**
  * Calculates the miniumum payload seen
@@ -7,7 +9,7 @@
  **/
 public class MinPayloadFunction extends PayloadFunction {
 
-    public float currentScore(int docId, String field, int numPayloadsSeen, float currentScore,
float currentPayloadScore) {
+    public float currentScore(int docId, String field, int start, int end, int numPayloadsSeen,
float currentScore, float currentPayloadScore) {
     return Math.min(currentPayloadScore, currentScore);
   }
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/payloads/PayloadFunction.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/payloads/PayloadFunction.java?rev=804178&r1=804177&r2=804178&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/payloads/PayloadFunction.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/payloads/PayloadFunction.java Fri
Aug 14 12:14:19 2009
@@ -16,6 +16,8 @@
  * limitations under the License.
  */
 
+import org.apache.lucene.index.Term;
+
 import java.io.Serializable;
 
 
@@ -37,13 +39,17 @@
   /**
    * Calculate the score up to this point for this doc and field
    * @param docId The current doc
-   * @param field The current field
+   * @param field The field
+   * @param start The start position of the matching Span
+   * @param end The end position of the matching Span
    * @param numPayloadsSeen The number of payloads seen so far
    * @param currentScore The current score so far
    * @param currentPayloadScore The score for the current payload
-   * @return The new current score
+   * @return The new current Score
+   *
+   * @see org.apache.lucene.search.spans.Spans
    */
-  public abstract float currentScore(int docId, String field, int numPayloadsSeen, float
currentScore, float currentPayloadScore);
+  public abstract float currentScore(int docId, String field, int start, int end, int numPayloadsSeen,
float currentScore, float currentPayloadScore);
 
   /**
    * Calculate the final score for all the payloads seen so far for this doc/field

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/payloads/BoostingFunctionTermQueryTest.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/payloads/BoostingFunctionTermQueryTest.java?rev=804178&r1=804177&r2=804178&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/payloads/BoostingFunctionTermQueryTest.java
(original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/payloads/BoostingFunctionTermQueryTest.java
Fri Aug 14 12:14:19 2009
@@ -262,7 +262,7 @@
   static class BoostingSimilarity extends DefaultSimilarity {
 
     // TODO: Remove warning after API has been finalized
-    public float scorePayload(int docId, String fieldName, byte[] payload, int offset, int
length) {
+    public float scorePayload(int docId, String fieldName, int start, int end, byte[] payload,
int offset, int length) {
       //we know it is size 4 here, so ignore the offset/length
       return payload[0];
     }

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestBoostingNearQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestBoostingNearQuery.java?rev=804178&r1=804177&r2=804178&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestBoostingNearQuery.java
(original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestBoostingNearQuery.java
Fri Aug 14 12:14:19 2009
@@ -184,10 +184,11 @@
 	// must be static for weight serialization tests 
 	static class BoostingSimilarity extends DefaultSimilarity {
 
-		public float scorePayload(int docId, String fieldName, byte[] payload, int offset, int
length) {
-			return payload[0];
-		}
-
+// TODO: Remove warning after API has been finalized
+    public float scorePayload(int docId, String fieldName, int start, int end, byte[] payload,
int offset, int length) {
+      //we know it is size 4 here, so ignore the offset/length
+      return payload[0];
+    }
 		//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 		//Make everything else 1 so we see the effect of the payload
 		//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestBoostingTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestBoostingTermQuery.java?rev=804178&r1=804177&r2=804178&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestBoostingTermQuery.java
(original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/payloads/TestBoostingTermQuery.java
Fri Aug 14 12:14:19 2009
@@ -206,15 +206,15 @@
     CheckHits.checkHitCollector(query, PayloadHelper.NO_PAYLOAD_FIELD, searcher, results);
   }
 
-  // must be static for weight serialization tests 
+  // must be static for weight serialization tests
   static class BoostingSimilarity extends DefaultSimilarity {
-
     // TODO: Remove warning after API has been finalized
-    public float scorePayload(int docId, String fieldName, byte[] payload, int offset, int
length) {
+    public float scorePayload(int docId, String fieldName, int start, int end, byte[] payload,
int offset, int length) {
       //we know it is size 4 here, so ignore the offset/length
       return payload[0];
     }
 
+
     //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     //Make everything else 1 so we see the effect of the payload
     //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!



Mime
View raw message