You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2023/10/17 12:13:27 UTC
[lucene] branch main updated: Speed up TestIndexOrDocValuesQuery. (#12672)
This is an automated email from the ASF dual-hosted git repository.
jpountz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/main by this push:
new f055ac6e168 Speed up TestIndexOrDocValuesQuery. (#12672)
f055ac6e168 is described below
commit f055ac6e16818bb40311a8ec162f933af00a4a6b
Author: Adrien Grand <jp...@gmail.com>
AuthorDate: Tue Oct 17 14:13:21 2023 +0200
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.
---
.../apache/lucene/search/TestIndexOrDocValuesQuery.java | 7 ++++---
.../java/org/apache/lucene/tests/search/QueryUtils.java | 17 +++++++----------
2 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestIndexOrDocValuesQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestIndexOrDocValuesQuery.java
index e24c0cdb7c8..57ad6e24c82 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestIndexOrDocValuesQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestIndexOrDocValuesQuery.java
@@ -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 {
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/search/QueryUtils.java b/lucene/test-framework/src/java/org/apache/lucene/tests/search/QueryUtils.java
index 0cd75f6b06c..5a454681f54 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/search/QueryUtils.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/search/QueryUtils.java
@@ -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) {