lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r781130 - in /lucene/java/trunk: ./ src/java/org/apache/lucene/search/ src/test/org/apache/lucene/search/
Date Tue, 02 Jun 2009 19:16:20 GMT
Author: mikemccand
Date: Tue Jun  2 19:16:20 2009
New Revision: 781130

URL: http://svn.apache.org/viewvc?rev=781130&view=rev
Log:
LUCENE-1656: don't compute scores by default when sorting by field

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/common-build.xml
    lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiSearcher.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestStressSort.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=781130&r1=781129&r2=781130&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Jun  2 19:16:20 2009
@@ -5,22 +5,29 @@
 
 Changes in backwards compatibility policy
 
- 1. LUCENE-1575: Searchable.search(Weight, Filter, int, Sort)
-    currently tracks document scores (including maxScore), and sets
-    the score in each returned FieldDoc.  However, in 3.0 it will stop
-    tracking document scores. If document scores tracking is still
-    needed, you can use Searchable.search(Weight, Filter, Collector)
+ 1. LUCENE-1575: Searchable.search(Weight, Filter, int, Sort) no
+    longer computes document scores of each hit, by default.  If
+    document scores tracking is still needed, you can call
+    IndexSearcher.setDefaultFieldSortScoring(true, true) to enable
+    both per-hit and maxScore tracking; however, this is deprecated
+    and will be removed in 3.0.
+
+    Alternatively, use Searchable.search(Weight, Filter, Collector)
     and pass in a TopFieldCollector instance, using the following code
     sample:
  
     <code>
       TopFieldCollector tfc = TopFieldCollector.create(sort, numHits, fillFields, 
                                                        true /* trackDocScores */,
-                                                       true /* trackMaxScore */);
-      searcher.search(weight, filter, tfc);
+                                                       true /* trackMaxScore */,
+						       false /* docsInOrder */);
+      searcher.search(query, tfc);
       TopDocs results = tfc.topDocs();
     </code>
 
+    Note that your Sort object cannot use SortField.AUTO when you
+    directly instantiate TopFieldCollector.
+
     Also, the method search(Weight, Filter, Collector) was added to
     the Searchable interface and the Searcher abstract class, to
     replace the deprecated HitCollector versions.  If you either

Modified: lucene/java/trunk/common-build.xml
URL: http://svn.apache.org/viewvc/lucene/java/trunk/common-build.xml?rev=781130&r1=781129&r2=781130&view=diff
==============================================================================
--- lucene/java/trunk/common-build.xml (original)
+++ lucene/java/trunk/common-build.xml Tue Jun  2 19:16:20 2009
@@ -42,7 +42,7 @@
   <property name="Name" value="Lucene"/>
   <property name="dev.version" value="2.9-dev"/>
   <property name="version" value="${dev.version}"/>
-  <property name="compatibility.tag" value="lucene_2_4_back_compat_tests_20090601a"/>
+  <property name="compatibility.tag" value="lucene_2_4_back_compat_tests_20090602"/>
   <property name="spec.version" value="${version}"/>	
   <property name="year" value="2000-${current.year}"/>
   <property name="final.name" value="lucene-${name}-${version}"/>

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java?rev=781130&r1=781129&r2=781130&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java Tue Jun  2 19:16:20
2009
@@ -225,14 +225,11 @@
       return (TopFieldDocs) collector.topDocs();
     }
     // Search each sub-reader
-    // TODO (3.0): by default we should create a TopFieldCollector which does
-    // not track document scores and maxScore. Currently the default is set to
-    // true, however it will change in 3.0.
     // TODO: The following should be changed to first obtain a Scorer and then ask it
     // if it's going to return in-order or out-of-order docs, and create TSDC
     // accordingly.
     TopFieldCollector collector = TopFieldCollector.create(sort, nDocs,
-        fillFields, true, true, false);
+        fillFields, fieldSortDoTrackScores, fieldSortDoMaxScore, false);
     search(weight, filter, collector);
     return (TopFieldDocs) collector.topDocs();
   }
@@ -299,4 +296,13 @@
   public Explanation explain(Weight weight, int doc) throws IOException {
     return weight.explain(reader, doc);
   }
+
+  private boolean fieldSortDoTrackScores;
+  private boolean fieldSortDoMaxScore;
+
+  /** @deprecated */
+  public void setDefaultFieldSortScoring(boolean doTrackScores, boolean doMaxScore) {
+    fieldSortDoTrackScores = doTrackScores;
+    fieldSortDoMaxScore = doMaxScore;
+  }
 }

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiSearcher.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiSearcher.java?rev=781130&r1=781129&r2=781130&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiSearcher.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestMultiSearcher.java Tue Jun  2
19:16:20 2009
@@ -120,7 +120,7 @@
 
         // iterating over the hit documents
         for (int i = 0; i < hits.length; i++) {
-            Document d = mSearcher.doc(hits[i].doc);
+          mSearcher.doc(hits[i].doc);
         }
         mSearcher.close();
 
@@ -149,8 +149,8 @@
 
         // iterating over the hit documents
         for (int i = 0; i < hits2.length; i++) {
-            // no exception should happen at this point
-            Document d = mSearcher2.doc(hits2[i].doc);
+          // no exception should happen at this point
+          mSearcher2.doc(hits2[i].doc);
         }
 
         // test the subSearcher() method:
@@ -194,7 +194,7 @@
 
         // iterating over the hit documents
         for (int i = 0; i < hits3.length; i++) {
-            Document d = mSearcher3.doc(hits3[i].doc);
+          mSearcher3.doc(hits3[i].doc);
         }
         mSearcher3.close();
         indexStoreA.close();
@@ -298,6 +298,7 @@
         initIndex(ramDirectory1, nDocs, false, "x"); // documents with two tokens "doc0"
and "x", "doc1" and x, etc...
         
         indexSearcher1=new IndexSearcher(ramDirectory1);
+        indexSearcher1.setDefaultFieldSortScoring(true, true);
         
         hits=indexSearcher1.search(query, null, 1000).scoreDocs;
         
@@ -325,7 +326,9 @@
         initIndex(ramDirectory2, nDocs, true, "x"); // documents with two tokens "doc0" and
"x", "doc1" and x, etc...
         
         indexSearcher1=new IndexSearcher(ramDirectory1);
+        indexSearcher1.setDefaultFieldSortScoring(true, true);
         indexSearcher2=new IndexSearcher(ramDirectory2);
+        indexSearcher2.setDefaultFieldSortScoring(true, true);
         
         Searcher searcher=getMultiSearcherInstance(new Searcher[] { indexSearcher1, indexSearcher2
});
         

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java?rev=781130&r1=781129&r2=781130&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 Tue Jun  2 19:16:20
2009
@@ -146,7 +146,9 @@
     }
     //writer.optimize ();
     writer.close ();
-    return new IndexSearcher (indexStore);
+    IndexSearcher s = new IndexSearcher (indexStore);
+    s.setDefaultFieldSortScoring(true, true);
+    return s;
   }
 
   private Searcher getFullIndex()

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestStressSort.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestStressSort.java?rev=781130&r1=781129&r2=781130&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestStressSort.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestStressSort.java Tue Jun  2 19:16:20
2009
@@ -157,18 +157,20 @@
     }
     writer.close();
     searcherMultiSegment = new IndexSearcher(dir);
+    searcherMultiSegment.setDefaultFieldSortScoring(true, true);
 
     dir2 = new MockRAMDirectory(dir);
     writer = new IndexWriter(dir2, new StandardAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
     writer.optimize();
     writer.close();
     searcherSingleSegment = new IndexSearcher(dir2);
-
+    searcherSingleSegment.setDefaultFieldSortScoring(true, true);
     dir3 = new MockRAMDirectory(dir);
     writer = new IndexWriter(dir3, new StandardAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
     writer.optimize(3);
     writer.close();
     searcherFewSegment = new IndexSearcher(dir3);
+    searcherFewSegment.setDefaultFieldSortScoring(true, true);
   }
 
   private void close() throws Throwable {



Mime
View raw message