gautamworah96 commented on a change in pull request #731: URL: https://github.com/apache/lucene/pull/731#discussion_r837090466
########## File path: lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestMultiRangeQueries.java ########## @@ -761,4 +764,103 @@ public void testEqualsAndHashCode() { assertNotEquals(query1.hashCode(), query3.hashCode()); } } + + public void testRewrite() throws IOException { + LongPointMultiRangeBuilder builder = new LongPointMultiRangeBuilder("ff", 1); + builder.add(new long[] {2}, new long[] {3}); + builder.add(new long[] {3}, new long[] {4}); + builder.add(new long[] {1}, new long[] {5}); + builder.add(new long[] {8}, new long[] {10}); + builder.add(new long[] {3}, new long[] {3}); + builder.add(new long[] {1}, new long[] {6}); + MultiRangeQuery multiRangeQuery = builder.build(); + Query query = multiRangeQuery.rewrite(null); + assertNotEquals(query, multiRangeQuery); + Query query1 = query.rewrite(null); + Assert.assertEquals(query1, query); + } + + public void testRandomRewrite() throws IOException { Review comment: `test rewrite query. the hit doc count of the rewritten query should be the same as origin query's.` -> `The hit doc count of the rewritten query should be the same as origin query's.` ########## File path: lucene/sandbox/src/java/org/apache/lucene/sandbox/search/MultiRangeQuery.java ########## @@ -163,6 +165,69 @@ public void visit(QueryVisitor visitor) { } } + /** + * merge its overlapping ranges and return a simpler but slightly different form by calling {@link + * #mergeOverlappingRanges} + */ + @Override + public Query rewrite(IndexReader reader) throws IOException { + if (numDims != 1) { + return this; + } + List<RangeClause> mergedRanges = mergeOverlappingRanges(rangeClauses, bytesPerDim); + if (mergedRanges != rangeClauses) { + return new MultiRangeQuery(field, numDims, bytesPerDim, mergedRanges) { + @Override + protected String toString(int dimension, byte[] value) { + return MultiRangeQuery.this.toString(dimension, value); + } + }; + } else { + return this; + } + } + + /** merge overlapping ranges to some unconnected ranges */ + public static List<RangeClause> mergeOverlappingRanges( Review comment: minor: `merge overlapping ranges to some unconnected ranges` -> `Merges overlapping ranges and returns unconnected ranges`. The `some` word in both the javadoc and the param description is redundant. -- 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