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()
|
||||
// relies on costs and PointValues.estimateCost so we need the default codec
|
||||
.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();
|
||||
if (i < 1000) {
|
||||
if (i < numDocs / 2) {
|
||||
doc.add(new StringField("f1", "bar", Store.NO));
|
||||
for (int j = 0; j < 500; j++) {
|
||||
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 LongField("f2", 2L, Store.NO));
|
||||
} else {
|
||||
|
|
|
@ -540,8 +540,10 @@ public class QueryUtils {
|
|||
s.search(
|
||||
q,
|
||||
new SimpleCollector() {
|
||||
private final Weight w = s.createWeight(rewritten, ScoreMode.COMPLETE, 1);
|
||||
private Scorable scorer;
|
||||
private int leafPtr;
|
||||
private long intervalTimes32 = 1 * 32;
|
||||
|
||||
@Override
|
||||
public void setScorer(Scorable scorer) {
|
||||
|
@ -552,10 +554,11 @@ public class QueryUtils {
|
|||
public void collect(int doc) throws IOException {
|
||||
float score = scorer.score();
|
||||
try {
|
||||
long startNS = System.nanoTime();
|
||||
for (int i = lastDoc[0] + 1; i <= doc; i++) {
|
||||
Weight w = s.createWeight(rewritten, ScoreMode.COMPLETE, 1);
|
||||
Scorer scorer = w.scorer(context.get(leafPtr));
|
||||
// The intervalTimes32 trick helps contain the runtime of this check: first we check
|
||||
// every single doc in the interval, then after 32 docs we check every 2 docs, etc.
|
||||
for (int i = lastDoc[0] + 1; i <= doc; i += intervalTimes32++ / 1024) {
|
||||
ScorerSupplier supplier = w.scorerSupplier(context.get(leafPtr));
|
||||
Scorer scorer = supplier.get(1L); // only checking one doc, so leadCost = 1
|
||||
assertTrue(
|
||||
"query collected " + doc + " but advance(" + i + ") says no more docs!",
|
||||
scorer.iterator().advance(i) != DocIdSetIterator.NO_MORE_DOCS);
|
||||
|
@ -579,12 +582,6 @@ public class QueryUtils {
|
|||
score,
|
||||
advanceScore,
|
||||
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;
|
||||
} catch (IOException e) {
|
||||
|
|
Loading…
Reference in New Issue