lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r332651 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/search/FieldSortedHitQueue.java src/test/org/apache/lucene/search/TestSort.java
Date Fri, 11 Nov 2005 21:19:10 GMT
Author: yonik
Date: Fri Nov 11 13:19:02 2005
New Revision: 332651

URL: http://svn.apache.org/viewcvs?rev=332651&view=rev
Log:
fix FieldSortedHitQueue.maxscore: LUCENE-462

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/search/FieldSortedHitQueue.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/CHANGES.txt?rev=332651&r1=332650&r2=332651&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Fri Nov 11 13:19:02 2005
@@ -249,6 +249,10 @@
 16. Fixed a sorting problem with MultiSearchers that can lead to
     missing or duplicate docs due to equal docs sorting in an arbitrary order.
     (Yonik Seeley, LUCENE-456)
+
+17. A single hit using the expert level sorted search methods
+    resulted in the score not being normalized.
+    (Yonik Seeley, LUCENE-462)
 	
 Optimizations
      

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/FieldSortedHitQueue.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/search/FieldSortedHitQueue.java?rev=332651&r1=332650&r2=332651&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/FieldSortedHitQueue.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/FieldSortedHitQueue.java Fri Nov 11
13:19:02 2005
@@ -68,11 +68,29 @@
   /** Stores the sort criteria being used. */
   protected SortField[] fields;
 
-  /** Stores the maximum score value encountered, for normalizing.
-   *  we only care about scores greater than 1.0 - if all the scores
-   *  are less than 1.0, we don't have to normalize. */
-  protected float maxscore = 1.0f;
+  /** Stores the maximum score value encountered, needed for normalizing. */
+  protected float maxscore = Float.NEGATIVE_INFINITY;
 
+  /** returns the maximum score encountered by elements inserted via insert()
+   */
+  public float getMaxScore() {
+    return maxscore;
+  }
+
+  // The signature of this method takes a FieldDoc in order to avoid
+  // the unneeded cast to retrieve the score.
+  // inherit javadoc
+  public boolean insert(FieldDoc fdoc) {
+    maxscore = Math.max(maxscore,fdoc.score);
+    return super.insert(fdoc);
+  }
+
+  // This overrides PriorityQueue.insert() so that insert(FieldDoc) that
+  // keeps track of the score isn't accidentally bypassed.  
+  // inherit javadoc
+  public boolean insert(Object fdoc) {
+    return insert((FieldDoc)fdoc);
+  }
 
   /**
    * Returns whether <code>a</code> is less relevant than <code>b</code>.
@@ -83,10 +101,6 @@
   protected boolean lessThan (final Object a, final Object b) {
     final ScoreDoc docA = (ScoreDoc) a;
     final ScoreDoc docB = (ScoreDoc) b;
-
-    // keep track of maximum score
-    if (docA.score > maxscore) maxscore = docA.score;
-    if (docB.score > maxscore) maxscore = docB.score;
 
     // run comparators
     final int n = comparators.length;

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java?rev=332651&r1=332650&r2=332651&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java Fri Nov 11 13:19:02
2005
@@ -516,7 +516,7 @@
 
     TopDocs docs2 = full.search(queryE, filt, nDocs, sort);
     
-    // assertEquals(docs1.scoreDocs[0].score, docs2.scoreDocs[0].score, 1e-6);
+    assertEquals(docs1.scoreDocs[0].score, docs2.scoreDocs[0].score, 1e-6);
   }
 
 



Mime
View raw message