Enhance XXXField#newRangeQuery (#12078)

Introduce IndexSortSortedNumericDocValuesRangeQuery to IntFiled#newRangeQuery and LongField#newRangeQuery
This commit is contained in:
Lu Xugang 2023-01-13 18:12:26 +08:00 committed by GitHub
parent aaab028266
commit 102622842b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 37 deletions

View File

@ -282,6 +282,7 @@ Optimizations
* GITHUB#12081: Small merging speedup on sorted indexes. (Adrien Grand) * GITHUB#12081: Small merging speedup on sorted indexes. (Adrien Grand)
* GITHUB#12078: Enhance XXXField#newRangeQuery. (Lu Xugang)
Other Other
--------------------- ---------------------

View File

@ -19,6 +19,7 @@ package org.apache.lucene.document;
import org.apache.lucene.index.DocValuesType; import org.apache.lucene.index.DocValuesType;
import org.apache.lucene.index.PointValues; import org.apache.lucene.index.PointValues;
import org.apache.lucene.search.IndexOrDocValuesQuery; import org.apache.lucene.search.IndexOrDocValuesQuery;
import org.apache.lucene.search.IndexSortSortedNumericDocValuesRangeQuery;
import org.apache.lucene.search.PointRangeQuery; import org.apache.lucene.search.PointRangeQuery;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.apache.lucene.search.SortField; import org.apache.lucene.search.SortField;
@ -105,9 +106,12 @@ public final class IntField extends Field {
*/ */
public static Query newRangeQuery(String field, int lowerValue, int upperValue) { public static Query newRangeQuery(String field, int lowerValue, int upperValue) {
PointRangeQuery.checkArgs(field, lowerValue, upperValue); PointRangeQuery.checkArgs(field, lowerValue, upperValue);
return new IndexOrDocValuesQuery( Query fallbackQuery =
IntPoint.newRangeQuery(field, lowerValue, upperValue), new IndexOrDocValuesQuery(
SortedNumericDocValuesField.newSlowRangeQuery(field, lowerValue, upperValue)); IntPoint.newRangeQuery(field, lowerValue, upperValue),
SortedNumericDocValuesField.newSlowRangeQuery(field, lowerValue, upperValue));
return new IndexSortSortedNumericDocValuesRangeQuery(
field, lowerValue, upperValue, fallbackQuery);
} }
/** /**

View File

@ -22,6 +22,7 @@ import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.BoostQuery; import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.IndexOrDocValuesQuery; import org.apache.lucene.search.IndexOrDocValuesQuery;
import org.apache.lucene.search.IndexSortSortedNumericDocValuesRangeQuery;
import org.apache.lucene.search.PointRangeQuery; import org.apache.lucene.search.PointRangeQuery;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.apache.lucene.search.SortField; import org.apache.lucene.search.SortField;
@ -108,9 +109,12 @@ public final class LongField extends Field {
*/ */
public static Query newRangeQuery(String field, long lowerValue, long upperValue) { public static Query newRangeQuery(String field, long lowerValue, long upperValue) {
PointRangeQuery.checkArgs(field, lowerValue, upperValue); PointRangeQuery.checkArgs(field, lowerValue, upperValue);
return new IndexOrDocValuesQuery( Query fallbackQuery =
LongPoint.newRangeQuery(field, lowerValue, upperValue), new IndexOrDocValuesQuery(
SortedNumericDocValuesField.newSlowRangeQuery(field, lowerValue, upperValue)); LongPoint.newRangeQuery(field, lowerValue, upperValue),
SortedNumericDocValuesField.newSlowRangeQuery(field, lowerValue, upperValue));
return new IndexSortSortedNumericDocValuesRangeQuery(
field, lowerValue, upperValue, fallbackQuery);
} }
/** /**

View File

@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.lucene.sandbox.search; package org.apache.lucene.search;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayDeque; import java.util.ArrayDeque;
@ -31,24 +31,7 @@ import org.apache.lucene.index.PointValues.IntersectVisitor;
import org.apache.lucene.index.PointValues.PointTree; import org.apache.lucene.index.PointValues.PointTree;
import org.apache.lucene.index.PointValues.Relation; import org.apache.lucene.index.PointValues.Relation;
import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.SortedNumericDocValues;
import org.apache.lucene.search.ConstantScoreScorer;
import org.apache.lucene.search.ConstantScoreWeight;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.FieldComparator;
import org.apache.lucene.search.FieldExistsQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.LeafFieldComparator;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryVisitor;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.ScorerSupplier;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.SortField.Type; import org.apache.lucene.search.SortField.Type;
import org.apache.lucene.search.SortedNumericSortField;
import org.apache.lucene.search.Weight;
import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.ArrayUtil.ByteArrayComparator; import org.apache.lucene.util.ArrayUtil.ByteArrayComparator;

View File

@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.lucene.sandbox.search; package org.apache.lucene.search;
import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.instanceOf;
@ -30,18 +30,6 @@ import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.FieldExistsQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.SortedNumericSortField;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.Weight;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.tests.analysis.MockAnalyzer; import org.apache.lucene.tests.analysis.MockAnalyzer;
import org.apache.lucene.tests.index.RandomIndexWriter; import org.apache.lucene.tests.index.RandomIndexWriter;