mirror of https://github.com/apache/lucene.git
LUCENE-7892: Add "slow" to factory methods of doc-values queries.
This commit is contained in:
parent
db71c5615a
commit
1e6e4022cf
|
@ -100,6 +100,10 @@ API Changes
|
|||
DoubleValuesSource extensions, or with the new ShapeValuesSource and
|
||||
ShapeValuesPredicate classes (Alan Woodward, David Smiley)
|
||||
|
||||
* LUCENE-7892: Doc-values query factory methods have been renamed so that their
|
||||
name contains "slow" in order to cleary indicate that they would usually be a
|
||||
bad choice. (Adrien Grand)
|
||||
|
||||
Bug Fixes
|
||||
|
||||
* LUCENE-7626: IndexWriter will no longer accept broken token offsets
|
||||
|
|
|
@ -78,7 +78,7 @@ public class NumericDocValuesField extends Field {
|
|||
* alongside a range query that executes on points, such as
|
||||
* {@link LongPoint#newRangeQuery}.
|
||||
*/
|
||||
public static Query newRangeQuery(String field, long lowerValue, long upperValue) {
|
||||
public static Query newSlowRangeQuery(String field, long lowerValue, long upperValue) {
|
||||
return new SortedNumericDocValuesRangeQuery(field, lowerValue, upperValue) {
|
||||
@Override
|
||||
SortedNumericDocValues getValues(LeafReader reader, String field) throws IOException {
|
||||
|
@ -99,7 +99,7 @@ public class NumericDocValuesField extends Field {
|
|||
* alongside a range query that executes on points, such as
|
||||
* {@link LongPoint#newExactQuery}.
|
||||
*/
|
||||
public static Query newExactQuery(String field, long value) {
|
||||
return newRangeQuery(field, value, value);
|
||||
public static Query newSlowExactQuery(String field, long value) {
|
||||
return newSlowRangeQuery(field, value, value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ public class SortedNumericDocValuesField extends Field {
|
|||
* alongside a range query that executes on points, such as
|
||||
* {@link LongPoint#newRangeQuery}.
|
||||
*/
|
||||
public static Query newRangeQuery(String field, long lowerValue, long upperValue) {
|
||||
public static Query newSlowRangeQuery(String field, long lowerValue, long upperValue) {
|
||||
return new SortedNumericDocValuesRangeQuery(field, lowerValue, upperValue) {
|
||||
@Override
|
||||
SortedNumericDocValues getValues(LeafReader reader, String field) throws IOException {
|
||||
|
@ -114,7 +114,7 @@ public class SortedNumericDocValuesField extends Field {
|
|||
* alongside a range query that executes on points, such as
|
||||
* {@link LongPoint#newExactQuery}.
|
||||
*/
|
||||
public static Query newExactQuery(String field, long value) {
|
||||
return newRangeQuery(field, value, value);
|
||||
public static Query newSlowExactQuery(String field, long value) {
|
||||
return newSlowRangeQuery(field, value, value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,9 +80,9 @@ public class TestDocValuesQueries extends LuceneTestCase {
|
|||
final Query q1 = LongPoint.newRangeQuery("idx", min, max);
|
||||
final Query q2;
|
||||
if (sortedNumeric) {
|
||||
q2 = SortedNumericDocValuesField.newRangeQuery("dv", min, max);
|
||||
q2 = SortedNumericDocValuesField.newSlowRangeQuery("dv", min, max);
|
||||
} else {
|
||||
q2 = NumericDocValuesField.newRangeQuery("dv", min, max);
|
||||
q2 = NumericDocValuesField.newSlowRangeQuery("dv", min, max);
|
||||
}
|
||||
assertSameMatches(searcher, q1, q2, false);
|
||||
}
|
||||
|
@ -185,11 +185,11 @@ public class TestDocValuesQueries extends LuceneTestCase {
|
|||
}
|
||||
|
||||
public void testEquals() {
|
||||
Query q1 = SortedNumericDocValuesField.newRangeQuery("foo", 3, 5);
|
||||
QueryUtils.checkEqual(q1, SortedNumericDocValuesField.newRangeQuery("foo", 3, 5));
|
||||
QueryUtils.checkUnequal(q1, SortedNumericDocValuesField.newRangeQuery("foo", 3, 6));
|
||||
QueryUtils.checkUnequal(q1, SortedNumericDocValuesField.newRangeQuery("foo", 4, 5));
|
||||
QueryUtils.checkUnequal(q1, SortedNumericDocValuesField.newRangeQuery("bar", 3, 5));
|
||||
Query q1 = SortedNumericDocValuesField.newSlowRangeQuery("foo", 3, 5);
|
||||
QueryUtils.checkEqual(q1, SortedNumericDocValuesField.newSlowRangeQuery("foo", 3, 5));
|
||||
QueryUtils.checkUnequal(q1, SortedNumericDocValuesField.newSlowRangeQuery("foo", 3, 6));
|
||||
QueryUtils.checkUnequal(q1, SortedNumericDocValuesField.newSlowRangeQuery("foo", 4, 5));
|
||||
QueryUtils.checkUnequal(q1, SortedNumericDocValuesField.newSlowRangeQuery("bar", 3, 5));
|
||||
|
||||
Query q2 = SortedSetDocValuesField.newRangeQuery("foo", new BytesRef("bar"), new BytesRef("baz"), true, true);
|
||||
QueryUtils.checkEqual(q2, SortedSetDocValuesField.newRangeQuery("foo", new BytesRef("bar"), new BytesRef("baz"), true, true));
|
||||
|
@ -199,7 +199,7 @@ public class TestDocValuesQueries extends LuceneTestCase {
|
|||
}
|
||||
|
||||
public void testToString() {
|
||||
Query q1 = SortedNumericDocValuesField.newRangeQuery("foo", 3, 5);
|
||||
Query q1 = SortedNumericDocValuesField.newSlowRangeQuery("foo", 3, 5);
|
||||
assertEquals("foo:[3 TO 5]", q1.toString());
|
||||
assertEquals("[3 TO 5]", q1.toString("foo"));
|
||||
assertEquals("foo:[3 TO 5]", q1.toString("bar"));
|
||||
|
@ -226,8 +226,8 @@ public class TestDocValuesQueries extends LuceneTestCase {
|
|||
iw.close();
|
||||
IndexSearcher searcher = newSearcher(reader);
|
||||
for (Query query : Arrays.asList(
|
||||
NumericDocValuesField.newRangeQuery("foo", 2, 4),
|
||||
SortedNumericDocValuesField.newRangeQuery("foo", 2, 4),
|
||||
NumericDocValuesField.newSlowRangeQuery("foo", 2, 4),
|
||||
SortedNumericDocValuesField.newSlowRangeQuery("foo", 2, 4),
|
||||
SortedDocValuesField.newRangeQuery("foo", new BytesRef("abc"), new BytesRef("bcd"), random().nextBoolean(), random().nextBoolean()),
|
||||
SortedSetDocValuesField.newRangeQuery("foo", new BytesRef("abc"), new BytesRef("bcd"), random().nextBoolean(), random().nextBoolean()))) {
|
||||
Weight w = searcher.createNormalizedWeight(query, random().nextBoolean());
|
||||
|
@ -255,12 +255,12 @@ public class TestDocValuesQueries extends LuceneTestCase {
|
|||
final long lo = NumericUtils.doubleToSortableLong(8.701032080293731E-226);
|
||||
final long hi = NumericUtils.doubleToSortableLong(2.0801416404385346E-41);
|
||||
|
||||
Query query = SortedNumericDocValuesField.newRangeQuery("dv", lo, hi);
|
||||
Query query = SortedNumericDocValuesField.newSlowRangeQuery("dv", lo, hi);
|
||||
// TODO: assert expected matches
|
||||
searcher.search(query, searcher.reader.maxDoc(), Sort.INDEXORDER);
|
||||
|
||||
// swap order, should still work
|
||||
query = SortedNumericDocValuesField.newRangeQuery("dv", hi, lo);
|
||||
query = SortedNumericDocValuesField.newSlowRangeQuery("dv", hi, lo);
|
||||
// TODO: assert expected matches
|
||||
searcher.search(query, searcher.reader.maxDoc(), Sort.INDEXORDER);
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ public class TestIndexOrDocValuesQuery extends LuceneTestCase {
|
|||
// The term query is more selective, so the IndexOrDocValuesQuery should use doc values
|
||||
final Query q1 = new BooleanQuery.Builder()
|
||||
.add(new TermQuery(new Term("f1", "foo")), Occur.MUST)
|
||||
.add(new IndexOrDocValuesQuery(LongPoint.newExactQuery("f2", 2), NumericDocValuesField.newRangeQuery("f2", 2L, 2L)), Occur.MUST)
|
||||
.add(new IndexOrDocValuesQuery(LongPoint.newExactQuery("f2", 2), NumericDocValuesField.newSlowRangeQuery("f2", 2L, 2L)), Occur.MUST)
|
||||
.build();
|
||||
|
||||
final Weight w1 = searcher.createNormalizedWeight(q1, random().nextBoolean());
|
||||
|
@ -74,7 +74,7 @@ public class TestIndexOrDocValuesQuery extends LuceneTestCase {
|
|||
// The term query is less selective, so the IndexOrDocValuesQuery should use points
|
||||
final Query q2 = new BooleanQuery.Builder()
|
||||
.add(new TermQuery(new Term("f1", "bar")), Occur.MUST)
|
||||
.add(new IndexOrDocValuesQuery(LongPoint.newExactQuery("f2", 42), NumericDocValuesField.newRangeQuery("f2", 42L, 42L)), Occur.MUST)
|
||||
.add(new IndexOrDocValuesQuery(LongPoint.newExactQuery("f2", 42), NumericDocValuesField.newSlowRangeQuery("f2", 42L, 42L)), Occur.MUST)
|
||||
.build();
|
||||
|
||||
final Weight w2 = searcher.createNormalizedWeight(q2, random().nextBoolean());
|
||||
|
|
|
@ -143,7 +143,7 @@ public class LatLonDocValuesField extends Field {
|
|||
* best used wrapped in an {@link IndexOrDocValuesQuery} alongside a
|
||||
* {@link LatLonPoint#newBoxQuery}.
|
||||
*/
|
||||
public static Query newBoxQuery(String field, double minLatitude, double maxLatitude, double minLongitude, double maxLongitude) {
|
||||
public static Query newSlowBoxQuery(String field, double minLatitude, double maxLatitude, double minLongitude, double maxLongitude) {
|
||||
// exact double values of lat=90.0D and lon=180.0D must be treated special as they are not represented in the encoding
|
||||
// and should not drag in extra bogus junk! TODO: should encodeCeil just throw ArithmeticException to be less trappy here?
|
||||
if (minLatitude == 90.0) {
|
||||
|
@ -175,7 +175,7 @@ public class LatLonDocValuesField extends Field {
|
|||
* @return query matching points within this distance
|
||||
* @throws IllegalArgumentException if {@code field} is null, location has invalid coordinates, or radius is invalid.
|
||||
*/
|
||||
public static Query newDistanceQuery(String field, double latitude, double longitude, double radiusMeters) {
|
||||
public static Query newSlowDistanceQuery(String field, double latitude, double longitude, double radiusMeters) {
|
||||
return new LatLonDocValuesDistanceQuery(field, latitude, longitude, radiusMeters);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,12 +36,12 @@ public class TestLatLonDocValuesQueries extends BaseGeoPointTestCase {
|
|||
|
||||
@Override
|
||||
protected Query newRectQuery(String field, double minLat, double maxLat, double minLon, double maxLon) {
|
||||
return LatLonDocValuesField.newBoxQuery(field, minLat, maxLat, minLon, maxLon);
|
||||
return LatLonDocValuesField.newSlowBoxQuery(field, minLat, maxLat, minLon, maxLon);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query newDistanceQuery(String field, double centerLat, double centerLon, double radiusMeters) {
|
||||
return LatLonDocValuesField.newDistanceQuery(field, centerLat, centerLon, radiusMeters);
|
||||
return LatLonDocValuesField.newSlowDistanceQuery(field, centerLat, centerLon, radiusMeters);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -266,7 +266,7 @@ public class EnumField extends PrimitiveFieldType {
|
|||
--upperValue;
|
||||
}
|
||||
}
|
||||
query = new ConstantScoreQuery(NumericDocValuesField.newRangeQuery(field.getName(), lowerValue, upperValue));
|
||||
query = new ConstantScoreQuery(NumericDocValuesField.newSlowRangeQuery(field.getName(), lowerValue, upperValue));
|
||||
} else {
|
||||
query = LegacyNumericRangeQuery.newIntRange(field.getName(), DEFAULT_PRECISION_STEP,
|
||||
min == null ? null : minValue,
|
||||
|
|
|
@ -155,16 +155,16 @@ public class LatLonPointSpatialField extends AbstractSpatialFieldType implements
|
|||
if (shape instanceof Circle) {
|
||||
Circle circle = (Circle) shape;
|
||||
double radiusMeters = circle.getRadius() * DistanceUtils.DEG_TO_KM * 1000;
|
||||
return LatLonDocValuesField.newDistanceQuery(getFieldName(),
|
||||
return LatLonDocValuesField.newSlowDistanceQuery(getFieldName(),
|
||||
circle.getCenter().getY(), circle.getCenter().getX(),
|
||||
radiusMeters);
|
||||
} else if (shape instanceof Rectangle) {
|
||||
Rectangle rect = (Rectangle) shape;
|
||||
return LatLonDocValuesField.newBoxQuery(getFieldName(),
|
||||
return LatLonDocValuesField.newSlowBoxQuery(getFieldName(),
|
||||
rect.getMinY(), rect.getMaxY(), rect.getMinX(), rect.getMaxX());
|
||||
} else if (shape instanceof Point) {
|
||||
Point point = (Point) shape;
|
||||
return LatLonDocValuesField.newDistanceQuery(getFieldName(),
|
||||
return LatLonDocValuesField.newSlowDistanceQuery(getFieldName(),
|
||||
point.getY(), point.getX(), 0);
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Shape " + shape.getClass() + " is not supported by " + getClass());
|
||||
|
|
|
@ -164,9 +164,9 @@ public abstract class NumericFieldType extends PrimitiveFieldType {
|
|||
}
|
||||
if (multiValued) {
|
||||
// In multiValued case use SortedNumericDocValuesField, this won't work for Trie*Fields wince they use BinaryDV in the multiValue case
|
||||
return SortedNumericDocValuesField.newRangeQuery(field, actualLowerValue, actualUpperValue);
|
||||
return SortedNumericDocValuesField.newSlowRangeQuery(field, actualLowerValue, actualUpperValue);
|
||||
} else {
|
||||
return NumericDocValuesField.newRangeQuery(field, actualLowerValue, actualUpperValue);
|
||||
return NumericDocValuesField.newSlowRangeQuery(field, actualLowerValue, actualUpperValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue