optimize field query/filter for numerics to only parse the string representation once
This commit is contained in:
parent
f745b80edb
commit
92c162d534
|
@ -27,6 +27,7 @@ import org.apache.lucene.search.NumericRangeFilter;
|
|||
import org.apache.lucene.search.NumericRangeQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -35,6 +36,7 @@ import org.elasticsearch.index.analysis.NumericIntegerAnalyzer;
|
|||
import org.elasticsearch.index.cache.field.data.FieldDataCache;
|
||||
import org.elasticsearch.index.field.data.FieldDataType;
|
||||
import org.elasticsearch.index.mapper.*;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.index.search.NumericRangeFieldDataFilter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -157,6 +159,12 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
|
|||
true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query fieldQuery(String value, @Nullable QueryParseContext context) {
|
||||
int iValue = Integer.parseInt(value);
|
||||
return NumericRangeQuery.newIntRange(names.indexName(), precisionStep,
|
||||
iValue, iValue, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query rangeQuery(String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) {
|
||||
|
@ -166,6 +174,13 @@ public class ByteFieldMapper extends NumberFieldMapper<Byte> {
|
|||
includeLower, includeUpper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter fieldFilter(String value, @Nullable QueryParseContext context) {
|
||||
int iValue = Integer.parseInt(value);
|
||||
return NumericRangeFilter.newIntRange(names.indexName(), precisionStep,
|
||||
iValue, iValue, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter rangeFilter(String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) {
|
||||
return NumericRangeFilter.newIntRange(names.indexName(), precisionStep,
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.lucene.search.NumericRangeFilter;
|
|||
import org.apache.lucene.search.NumericRangeQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.Numbers;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -35,6 +36,7 @@ import org.elasticsearch.index.analysis.NumericDoubleAnalyzer;
|
|||
import org.elasticsearch.index.cache.field.data.FieldDataCache;
|
||||
import org.elasticsearch.index.field.data.FieldDataType;
|
||||
import org.elasticsearch.index.mapper.*;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.index.search.NumericRangeFieldDataFilter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -154,6 +156,13 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
|
|||
true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query fieldQuery(String value, @Nullable QueryParseContext context) {
|
||||
double dValue = Double.parseDouble(value);
|
||||
return NumericRangeQuery.newDoubleRange(names.indexName(), precisionStep,
|
||||
dValue, dValue, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query rangeQuery(String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) {
|
||||
return NumericRangeQuery.newDoubleRange(names.indexName(), precisionStep,
|
||||
|
@ -162,6 +171,13 @@ public class DoubleFieldMapper extends NumberFieldMapper<Double> {
|
|||
includeLower, includeUpper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter fieldFilter(String value, @Nullable QueryParseContext context) {
|
||||
double dValue = Double.parseDouble(value);
|
||||
return NumericRangeFilter.newDoubleRange(names.indexName(), precisionStep,
|
||||
dValue, dValue, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter rangeFilter(String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) {
|
||||
return NumericRangeFilter.newDoubleRange(names.indexName(), precisionStep,
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.lucene.search.NumericRangeFilter;
|
|||
import org.apache.lucene.search.NumericRangeQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.Numbers;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
@ -36,6 +37,7 @@ import org.elasticsearch.index.analysis.NumericFloatAnalyzer;
|
|||
import org.elasticsearch.index.cache.field.data.FieldDataCache;
|
||||
import org.elasticsearch.index.field.data.FieldDataType;
|
||||
import org.elasticsearch.index.mapper.*;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.index.search.NumericRangeFieldDataFilter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -153,6 +155,13 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
|
|||
true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query fieldQuery(String value, @Nullable QueryParseContext context) {
|
||||
float fValue = Float.parseFloat(value);
|
||||
return NumericRangeQuery.newFloatRange(names.indexName(), precisionStep,
|
||||
fValue, fValue, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query rangeQuery(String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) {
|
||||
return NumericRangeQuery.newFloatRange(names.indexName(), precisionStep,
|
||||
|
@ -161,6 +170,13 @@ public class FloatFieldMapper extends NumberFieldMapper<Float> {
|
|||
includeLower, includeUpper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter fieldFilter(String value, @Nullable QueryParseContext context) {
|
||||
float fValue = Float.parseFloat(value);
|
||||
return NumericRangeFilter.newFloatRange(names.indexName(), precisionStep,
|
||||
fValue, fValue, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter rangeFilter(String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) {
|
||||
return NumericRangeFilter.newFloatRange(names.indexName(), precisionStep,
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.lucene.search.NumericRangeFilter;
|
|||
import org.apache.lucene.search.NumericRangeQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.Numbers;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
@ -36,6 +37,7 @@ import org.elasticsearch.index.analysis.NumericIntegerAnalyzer;
|
|||
import org.elasticsearch.index.cache.field.data.FieldDataCache;
|
||||
import org.elasticsearch.index.field.data.FieldDataType;
|
||||
import org.elasticsearch.index.mapper.*;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.index.search.NumericRangeFieldDataFilter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -158,6 +160,13 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
|
|||
true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query fieldQuery(String value, @Nullable QueryParseContext context) {
|
||||
int iValue = Integer.parseInt(value);
|
||||
return NumericRangeQuery.newIntRange(names.indexName(), precisionStep,
|
||||
iValue, iValue, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query rangeQuery(String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) {
|
||||
return NumericRangeQuery.newIntRange(names.indexName(), precisionStep,
|
||||
|
@ -166,6 +175,13 @@ public class IntegerFieldMapper extends NumberFieldMapper<Integer> {
|
|||
includeLower, includeUpper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter fieldFilter(String value, @Nullable QueryParseContext context) {
|
||||
int iValue = Integer.parseInt(value);
|
||||
return NumericRangeFilter.newIntRange(names.indexName(), precisionStep,
|
||||
iValue, iValue, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter rangeFilter(String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) {
|
||||
return NumericRangeFilter.newIntRange(names.indexName(), precisionStep,
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.lucene.search.NumericRangeFilter;
|
|||
import org.apache.lucene.search.NumericRangeQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.Numbers;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
@ -36,6 +37,7 @@ import org.elasticsearch.index.analysis.NumericLongAnalyzer;
|
|||
import org.elasticsearch.index.cache.field.data.FieldDataCache;
|
||||
import org.elasticsearch.index.field.data.FieldDataType;
|
||||
import org.elasticsearch.index.mapper.*;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.index.search.NumericRangeFieldDataFilter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -158,6 +160,13 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
|
|||
true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query fieldQuery(String value, @Nullable QueryParseContext context) {
|
||||
long iValue = Long.parseLong(value);
|
||||
return NumericRangeQuery.newLongRange(names.indexName(), precisionStep,
|
||||
iValue, iValue, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query rangeQuery(String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) {
|
||||
return NumericRangeQuery.newLongRange(names.indexName(), precisionStep,
|
||||
|
@ -166,6 +175,13 @@ public class LongFieldMapper extends NumberFieldMapper<Long> {
|
|||
includeLower, includeUpper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter fieldFilter(String value, @Nullable QueryParseContext context) {
|
||||
long iValue = Long.parseLong(value);
|
||||
return NumericRangeFilter.newLongRange(names.indexName(), precisionStep,
|
||||
iValue, iValue, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter rangeFilter(String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) {
|
||||
return NumericRangeFilter.newLongRange(names.indexName(), precisionStep,
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.lucene.search.NumericRangeFilter;
|
|||
import org.apache.lucene.search.NumericRangeQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.Numbers;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
@ -36,6 +37,7 @@ import org.elasticsearch.index.analysis.NumericIntegerAnalyzer;
|
|||
import org.elasticsearch.index.cache.field.data.FieldDataCache;
|
||||
import org.elasticsearch.index.field.data.FieldDataType;
|
||||
import org.elasticsearch.index.mapper.*;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.index.search.NumericRangeFieldDataFilter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -158,6 +160,13 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
|
|||
true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query fieldQuery(String value, @Nullable QueryParseContext context) {
|
||||
int iValue = Integer.parseInt(value);
|
||||
return NumericRangeQuery.newIntRange(names.indexName(), precisionStep,
|
||||
iValue, iValue, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query rangeQuery(String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) {
|
||||
return NumericRangeQuery.newIntRange(names.indexName(), precisionStep,
|
||||
|
@ -166,6 +175,13 @@ public class ShortFieldMapper extends NumberFieldMapper<Short> {
|
|||
includeLower, includeUpper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter fieldFilter(String value, @Nullable QueryParseContext context) {
|
||||
int iValue = Integer.parseInt(value);
|
||||
return NumericRangeFilter.newIntRange(names.indexName(), precisionStep,
|
||||
iValue, iValue, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter rangeFilter(String lowerTerm, String upperTerm, boolean includeLower, boolean includeUpper) {
|
||||
return NumericRangeFilter.newIntRange(names.indexName(), precisionStep,
|
||||
|
|
Loading…
Reference in New Issue