Skip to content

Commit

Permalink
Updating exact match queries
Browse files Browse the repository at this point in the history
Signed-off-by: Harsha Vamsi Kalluri <[email protected]>
  • Loading branch information
harshavamsi committed Nov 14, 2023
1 parent c676479 commit 57ec29e
Showing 1 changed file with 50 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,16 @@ public Float parse(XContentParser parser, boolean coerce) throws IOException {
}

@Override
public Query termQuery(String field, Object value) {
public Query termQuery(String field, Object value, Boolean hasDocValues) {
float v = parse(value, false);
return HalfFloatPoint.newExactQuery(field, v);
Query query = HalfFloatPoint.newExactQuery(field, v);
if(hasDocValues){
Query dvQuery = SortedNumericDocValuesField.newSlowExactQuery(
field, HalfFloatPoint.halfFloatToSortableShort(v)
);
query = new IndexOrDocValuesQuery(query, dvQuery);
}
return query;
}

@Override
Expand Down Expand Up @@ -309,9 +316,15 @@ public Float parse(XContentParser parser, boolean coerce) throws IOException {
}

@Override
public Query termQuery(String field, Object value) {
public Query termQuery(String field, Object value, Boolean hasDocValues) {
float v = parse(value, false);
return FloatPoint.newExactQuery(field, v);
Query query = FloatPoint.newExactQuery(field, v);
if(hasDocValues){
Query dvQuery = SortedNumericDocValuesField.newSlowExactQuery(field,
NumericUtils.floatToSortableInt(v));
query = new IndexOrDocValuesQuery(query, dvQuery);
}
return query;
}

@Override
Expand Down Expand Up @@ -406,9 +419,15 @@ public Double parse(XContentParser parser, boolean coerce) throws IOException {
}

@Override
public Query termQuery(String field, Object value) {
public Query termQuery(String field, Object value, Boolean hasDocValues) {
double v = parse(value, false);
return DoublePoint.newExactQuery(field, v);
Query query = DoublePoint.newExactQuery(field, v);
if(hasDocValues){
Query dvQuery = SortedNumericDocValuesField.newSlowExactQuery(field,
NumericUtils.doubleToSortableLong(v));
query = new IndexOrDocValuesQuery(query, dvQuery);
}
return query;
}

@Override
Expand Down Expand Up @@ -504,8 +523,8 @@ public Short parse(XContentParser parser, boolean coerce) throws IOException {
}

@Override
public Query termQuery(String field, Object value) {
return INTEGER.termQuery(field, value);
public Query termQuery(String field, Object value, Boolean hasDocValues) {
return INTEGER.termQuery(field, value, hasDocValues);
}

@Override
Expand Down Expand Up @@ -571,8 +590,8 @@ public Short parse(XContentParser parser, boolean coerce) throws IOException {
}

@Override
public Query termQuery(String field, Object value) {
return INTEGER.termQuery(field, value);
public Query termQuery(String field, Object value, Boolean hasDocValues) {
return INTEGER.termQuery(field, value, hasDocValues);
}

@Override
Expand Down Expand Up @@ -638,12 +657,17 @@ public Integer parse(XContentParser parser, boolean coerce) throws IOException {
}

@Override
public Query termQuery(String field, Object value) {
public Query termQuery(String field, Object value, Boolean hasDocValues) {
if (hasDecimalPart(value)) {
return Queries.newMatchNoDocsQuery("Value [" + value + "] has a decimal part");
}
int v = parse(value, true);
return IntPoint.newExactQuery(field, v);
Query query = IntPoint.newExactQuery(field, v);
if(hasDocValues){
Query dvQuery = SortedNumericDocValuesField.newSlowExactQuery(field, v);
query = new IndexOrDocValuesQuery(query, dvQuery);
}
return query;
}

@Override
Expand Down Expand Up @@ -752,12 +776,17 @@ public Long parse(XContentParser parser, boolean coerce) throws IOException {
}

@Override
public Query termQuery(String field, Object value) {
public Query termQuery(String field, Object value, Boolean hasDocValues) {
if (hasDecimalPart(value)) {
return Queries.newMatchNoDocsQuery("Value [" + value + "] has a decimal part");
}
long v = parse(value, true);
return LongPoint.newExactQuery(field, v);
Query query = LongPoint.newExactQuery(field, v);
if(hasDocValues){
Query dvQuery = SortedNumericDocValuesField.newSlowExactQuery(field, v);
query = new IndexOrDocValuesQuery(query, dvQuery);
}
return query;
}

@Override
Expand Down Expand Up @@ -841,12 +870,12 @@ public BigInteger parse(XContentParser parser, boolean coerce) throws IOExceptio
}

@Override
public Query termQuery(String field, Object value) {
public Query termQuery(String field, Object value, Boolean hasDocValues) {
if (hasDecimalPart(value)) {
return Queries.newMatchNoDocsQuery("Value [" + value + "] has a decimal part");
}
BigInteger v = parse(value, true);
return BigIntegerPoint.newExactQuery(field, v);
return UNSIGNED_LONG.rangeQuery(field, v, v, true, true, hasDocValues, null);
}

@Override
Expand Down Expand Up @@ -941,7 +970,7 @@ public final TypeParser parser() {
return parser;
}

public abstract Query termQuery(String field, Object value);
public abstract Query termQuery(String field, Object value, Boolean hasDocValues);

public abstract Query termsQuery(String field, List<Object> values);

Expand Down Expand Up @@ -1226,8 +1255,8 @@ public NumericType numericType() {

@Override
public Query termQuery(Object value, QueryShardContext context) {
failIfNotIndexed();
Query query = type.termQuery(name(), value);
failIfNotIndexedAndNoDocValues();
Query query = type.termQuery(name(), value, hasDocValues());
if (boost() != 1f) {
query = new BoostQuery(query, boost());
}
Expand All @@ -1236,7 +1265,7 @@ public Query termQuery(Object value, QueryShardContext context) {

@Override
public Query termsQuery(List values, QueryShardContext context) {
failIfNotIndexed();
failIfNotIndexedAndNoDocValues();
Query query = type.termsQuery(name(), values);
if (boost() != 1f) {
query = new BoostQuery(query, boost());
Expand All @@ -1246,7 +1275,7 @@ public Query termsQuery(List values, QueryShardContext context) {

@Override
public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, QueryShardContext context) {
failIfNotIndexed();
failIfNotIndexedAndNoDocValues();
Query query = type.rangeQuery(name(), lowerTerm, upperTerm, includeLower, includeUpper, hasDocValues(), context);
if (boost() != 1f) {
query = new BoostQuery(query, boost());
Expand Down

0 comments on commit 57ec29e

Please sign in to comment.