Index: CHANGES.txt =================================================================== --- CHANGES.txt (revision 778813) +++ CHANGES.txt (working copy) @@ -5,22 +5,26 @@ 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) - and pass in a TopFieldCollector instance, using the following code - sample: + 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. Alternatively, use + Searchable.search(Weight, Filter, Collector) and pass in a + TopFieldCollector instance, using the following code sample: 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(); + 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 Index: src/test/org/apache/lucene/search/TestSort.java =================================================================== --- src/test/org/apache/lucene/search/TestSort.java (revision 779103) +++ src/test/org/apache/lucene/search/TestSort.java (working copy) @@ -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() Index: src/test/org/apache/lucene/search/TestMultiSearcher.java =================================================================== --- src/test/org/apache/lucene/search/TestMultiSearcher.java (revision 778490) +++ src/test/org/apache/lucene/search/TestMultiSearcher.java (working copy) @@ -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 }); Index: src/test/org/apache/lucene/search/TestStressSort.java =================================================================== --- src/test/org/apache/lucene/search/TestStressSort.java (revision 778490) +++ src/test/org/apache/lucene/search/TestStressSort.java (working copy) @@ -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 { Index: src/java/org/apache/lucene/search/IndexSearcher.java =================================================================== --- src/java/org/apache/lucene/search/IndexSearcher.java (revision 778490) +++ src/java/org/apache/lucene/search/IndexSearcher.java (working copy) @@ -200,7 +200,7 @@ // 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(); } @@ -267,4 +267,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; + } }