mirror of https://github.com/apache/lucene.git
LUCENE-1656: don't compute scores by default when sorting by field
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@781130 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
475b5dc08f
commit
73fd2318fd
21
CHANGES.txt
21
CHANGES.txt
|
@ -5,22 +5,29 @@ $Id$
|
|||
|
||||
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
|
||||
|
|
|
@ -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}"/>
|
||||
|
|
|
@ -225,14 +225,11 @@ public class IndexSearcher extends Searcher {
|
|||
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 class IndexSearcher extends Searcher {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ public class TestMultiSearcher extends LuceneTestCase
|
|||
|
||||
// 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 @@ public class TestMultiSearcher extends LuceneTestCase
|
|||
|
||||
// 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 @@ public class TestMultiSearcher extends LuceneTestCase
|
|||
|
||||
// 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 @@ public class TestMultiSearcher extends LuceneTestCase
|
|||
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 @@ public class TestMultiSearcher extends LuceneTestCase
|
|||
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 });
|
||||
|
||||
|
|
|
@ -146,7 +146,9 @@ public class TestSort extends LuceneTestCase implements Serializable {
|
|||
}
|
||||
//writer.optimize ();
|
||||
writer.close ();
|
||||
return new IndexSearcher (indexStore);
|
||||
IndexSearcher s = new IndexSearcher (indexStore);
|
||||
s.setDefaultFieldSortScoring(true, true);
|
||||
return s;
|
||||
}
|
||||
|
||||
private Searcher getFullIndex()
|
||||
|
|
|
@ -157,18 +157,20 @@ public class TestStressSort extends LuceneTestCase {
|
|||
}
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue