mirror of https://github.com/apache/lucene.git
Speed up TestIndexOrDocValuesQuery. (#12672)
This changes the following: - fewer docs indexed in non-nightly runs, - `QueryUtils#checkFirstSkipTo` uses the `ScorerSupplier` API to convey it will only check one doc, - `QueryUtils#checkFirstSkipTo` no longer relies on timing to run in a reasonably amount of time.
This commit is contained in:
parent
8961dda2a4
commit
f055ac6e16
|
@ -112,14 +112,15 @@ public class TestIndexOrDocValuesQuery extends LuceneTestCase {
|
||||||
newIndexWriterConfig()
|
newIndexWriterConfig()
|
||||||
// relies on costs and PointValues.estimateCost so we need the default codec
|
// relies on costs and PointValues.estimateCost so we need the default codec
|
||||||
.setCodec(TestUtil.getDefaultCodec()));
|
.setCodec(TestUtil.getDefaultCodec()));
|
||||||
for (int i = 0; i < 2000; ++i) {
|
final int numDocs = atLeast(1000);
|
||||||
|
for (int i = 0; i < numDocs; ++i) {
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
if (i < 1000) {
|
if (i < numDocs / 2) {
|
||||||
doc.add(new StringField("f1", "bar", Store.NO));
|
doc.add(new StringField("f1", "bar", Store.NO));
|
||||||
for (int j = 0; j < 500; j++) {
|
for (int j = 0; j < 500; j++) {
|
||||||
doc.add(new LongField("f2", 42L, Store.NO));
|
doc.add(new LongField("f2", 42L, Store.NO));
|
||||||
}
|
}
|
||||||
} else if (i == 1001) {
|
} else if (i == numDocs / 2) {
|
||||||
doc.add(new StringField("f1", "foo", Store.NO));
|
doc.add(new StringField("f1", "foo", Store.NO));
|
||||||
doc.add(new LongField("f2", 2L, Store.NO));
|
doc.add(new LongField("f2", 2L, Store.NO));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -540,8 +540,10 @@ public class QueryUtils {
|
||||||
s.search(
|
s.search(
|
||||||
q,
|
q,
|
||||||
new SimpleCollector() {
|
new SimpleCollector() {
|
||||||
|
private final Weight w = s.createWeight(rewritten, ScoreMode.COMPLETE, 1);
|
||||||
private Scorable scorer;
|
private Scorable scorer;
|
||||||
private int leafPtr;
|
private int leafPtr;
|
||||||
|
private long intervalTimes32 = 1 * 32;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setScorer(Scorable scorer) {
|
public void setScorer(Scorable scorer) {
|
||||||
|
@ -552,10 +554,11 @@ public class QueryUtils {
|
||||||
public void collect(int doc) throws IOException {
|
public void collect(int doc) throws IOException {
|
||||||
float score = scorer.score();
|
float score = scorer.score();
|
||||||
try {
|
try {
|
||||||
long startNS = System.nanoTime();
|
// The intervalTimes32 trick helps contain the runtime of this check: first we check
|
||||||
for (int i = lastDoc[0] + 1; i <= doc; i++) {
|
// every single doc in the interval, then after 32 docs we check every 2 docs, etc.
|
||||||
Weight w = s.createWeight(rewritten, ScoreMode.COMPLETE, 1);
|
for (int i = lastDoc[0] + 1; i <= doc; i += intervalTimes32++ / 1024) {
|
||||||
Scorer scorer = w.scorer(context.get(leafPtr));
|
ScorerSupplier supplier = w.scorerSupplier(context.get(leafPtr));
|
||||||
|
Scorer scorer = supplier.get(1L); // only checking one doc, so leadCost = 1
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"query collected " + doc + " but advance(" + i + ") says no more docs!",
|
"query collected " + doc + " but advance(" + i + ") says no more docs!",
|
||||||
scorer.iterator().advance(i) != DocIdSetIterator.NO_MORE_DOCS);
|
scorer.iterator().advance(i) != DocIdSetIterator.NO_MORE_DOCS);
|
||||||
|
@ -579,12 +582,6 @@ public class QueryUtils {
|
||||||
score,
|
score,
|
||||||
advanceScore,
|
advanceScore,
|
||||||
maxDiff);
|
maxDiff);
|
||||||
|
|
||||||
// Hurry things along if they are going slow (eg
|
|
||||||
// if you got SimpleText codec this will kick in):
|
|
||||||
if (i < doc && System.nanoTime() - startNS > 5_000_000) {
|
|
||||||
i = doc - 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
lastDoc[0] = doc;
|
lastDoc[0] = doc;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
Loading…
Reference in New Issue