jpountz commented on a change in pull request #731: URL: https://github.com/apache/lucene/pull/731#discussion_r838348390
########## File path: lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestMultiRangeQueries.java ########## @@ -761,4 +763,90 @@ public void testEqualsAndHashCode() { assertNotEquals(query1.hashCode(), query3.hashCode()); } } + + private void addRandomDocs(RandomIndexWriter w) throws IOException { + Random random = random(); + for (int i = 0; i < random.nextInt(100, 500); i++) { Review comment: Let's not re-compute `nextInt` on every iteration. ```suggestion for (int i = 0, end = random.nextInt(100, 500); i < end; i++) { ``` ########## File path: lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestMultiRangeQueries.java ########## @@ -761,4 +763,90 @@ public void testEqualsAndHashCode() { assertNotEquals(query1.hashCode(), query3.hashCode()); } } + + private void addRandomDocs(RandomIndexWriter w) throws IOException { + Random random = random(); + for (int i = 0; i < random.nextInt(100, 500); i++) { + int numPoints = RandomNumbers.randomIntBetween(random(), 1, 200); + long value = RandomNumbers.randomLongBetween(random(), 0, 2000); + for (int j = 0; j < numPoints; j++) { + Document doc = new Document(); + doc.add(new LongPoint("point", value)); + w.addDocument(doc); + } + } + w.flush(); + w.forceMerge(1); + } + + /** The hit doc count of the rewritten query should be the same as origin query's */ + public void testRandomRewrite() throws IOException { + Directory dir = newDirectory(); + RandomIndexWriter w = new RandomIndexWriter(random(), dir); + int dims = 1; + addRandomDocs(w); + Random random = random(); + + IndexReader reader = w.getReader(); + IndexSearcher searcher = newSearcher(reader); + int numIters = random.nextInt(200); Review comment: we'd usually rather use `atLeast` to compute numbers of iterations, e.g. ```suggestion int numIters = atLeast(100); ``` ########## File path: lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestMultiRangeQueries.java ########## @@ -761,4 +763,90 @@ public void testEqualsAndHashCode() { assertNotEquals(query1.hashCode(), query3.hashCode()); } } + + private void addRandomDocs(RandomIndexWriter w) throws IOException { + Random random = random(); + for (int i = 0; i < random.nextInt(100, 500); i++) { + int numPoints = RandomNumbers.randomIntBetween(random(), 1, 200); + long value = RandomNumbers.randomLongBetween(random(), 0, 2000); + for (int j = 0; j < numPoints; j++) { + Document doc = new Document(); + doc.add(new LongPoint("point", value)); + w.addDocument(doc); + } + } + w.flush(); + w.forceMerge(1); + } + + /** The hit doc count of the rewritten query should be the same as origin query's */ + public void testRandomRewrite() throws IOException { + Directory dir = newDirectory(); + RandomIndexWriter w = new RandomIndexWriter(random(), dir); + int dims = 1; + addRandomDocs(w); + Random random = random(); + + IndexReader reader = w.getReader(); + IndexSearcher searcher = newSearcher(reader); + int numIters = random.nextInt(200); + + for (int n = 0; n < numIters; n++) { + int numRanges = RandomNumbers.randomIntBetween(random(), 1, 20); + LongPointMultiRangeBuilder builder1 = new LongPointMultiRangeBuilder("point", dims); + for (int i = 0; i < numRanges; i++) { + long[] lower = new long[dims]; + long[] upper = new long[dims]; + for (int j = 0; j < dims; j++) { + lower[j] = RandomNumbers.randomLongBetween(random(), 0, 2000); + upper[j] = lower[j] + RandomNumbers.randomLongBetween(random(), 0, 2000); + } + builder1.add(lower, upper); + } + + MultiRangeQuery multiRangeQuery = builder1.build(); + MultiRangeQuery rewriteMultiRangeQuery = (MultiRangeQuery) multiRangeQuery.rewrite(reader); + int count = searcher.count(multiRangeQuery); + int rewriteCount = searcher.count(rewriteMultiRangeQuery); + assertEquals(rewriteCount, count); Review comment: Actually this test doesn't verify anything since `IndexSearcher#count` will call `rewrite` under the hood. I think you would need to compare the `MultiRangeQuery` against a disjunction of `PointRangeQuery` like you did in `testOneDimensionCount`. Also, `IndexSearcher#count` uses `Weight#count` under the hood, so maybe use a `TotalHitCountCollectorManager` to force `IndexSearcher` to iterate over all matches for the counting? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org