Apply boost only once for distance_feature query (#63767)
Currently if distance_feature query contains boost, it incorrectly gets applied twice: in AbstractQueryBuilder::toQuery and we also pass this boost to Lucene's LongPoint.newDistanceFeatureQuery. As a result we get incorrect scores. This fixes this error to ensure that boost is applied only once. Closes #63691
This commit is contained in:
parent
179c6d4014
commit
c0c1a7a9a6
|
@ -1,3 +1,14 @@
|
|||
[[release-notes-7.10.1]]
|
||||
== {es} version 7.10.1
|
||||
|
||||
[[bug-7.10.1]]
|
||||
[float]
|
||||
=== Bug fixes
|
||||
|
||||
Search::
|
||||
* Apply boost only once for distance_feature query {es-pull}63767[#63767]
|
||||
|
||||
|
||||
[[release-notes-7.10.0]]
|
||||
== {es} version 7.10.0
|
||||
|
||||
|
|
|
@ -112,7 +112,8 @@ public class DistanceFeatureQueryBuilder extends AbstractQueryBuilder<DistanceFe
|
|||
if (fieldType == null) {
|
||||
return Queries.newMatchNoDocsQuery("Can't run [" + NAME + "] query on unmapped fields!");
|
||||
}
|
||||
return fieldType.distanceFeatureQuery(origin.origin(), pivot, boost, context);
|
||||
// As we already apply boost in AbstractQueryBuilder::toQuery, we always passing a boost of 1.0 to distanceFeatureQuery
|
||||
return fieldType.distanceFeatureQuery(origin.origin(), pivot, 1.0f, context);
|
||||
}
|
||||
|
||||
String fieldName() {
|
||||
|
|
|
@ -78,12 +78,11 @@ public class DistanceFeatureQueryBuilderTests extends AbstractQueryTestCase<Dist
|
|||
String fieldName = expectedFieldName(queryBuilder.fieldName());
|
||||
Object origin = queryBuilder.origin().origin();
|
||||
String pivot = queryBuilder.pivot();
|
||||
float boost = queryBuilder.boost;
|
||||
final Query expectedQuery;
|
||||
if (fieldName.equals(GEO_POINT_FIELD_NAME)) {
|
||||
GeoPoint originGeoPoint = (origin instanceof GeoPoint)? (GeoPoint) origin : GeoUtils.parseFromString((String) origin);
|
||||
double pivotDouble = DistanceUnit.DEFAULT.parse(pivot, DistanceUnit.DEFAULT);
|
||||
expectedQuery = LatLonPoint.newDistanceFeatureQuery(fieldName, boost, originGeoPoint.lat(), originGeoPoint.lon(), pivotDouble);
|
||||
expectedQuery = LatLonPoint.newDistanceFeatureQuery(fieldName, 1.0f, originGeoPoint.lat(), originGeoPoint.lon(), pivotDouble);
|
||||
} else { // if (fieldName.equals(DATE_FIELD_NAME))
|
||||
MapperService mapperService = context.getMapperService();
|
||||
DateFieldType fieldType = (DateFieldType) mapperService.fieldType(fieldName);
|
||||
|
@ -95,7 +94,7 @@ public class DistanceFeatureQueryBuilderTests extends AbstractQueryTestCase<Dist
|
|||
} else { // NANOSECONDS
|
||||
pivotLong = pivotVal.getNanos();
|
||||
}
|
||||
expectedQuery = LongPoint.newDistanceFeatureQuery(fieldName, boost, originLong, pivotLong);
|
||||
expectedQuery = LongPoint.newDistanceFeatureQuery(fieldName, 1.0f, originLong, pivotLong);
|
||||
}
|
||||
assertEquals(expectedQuery, query);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue