jenkins-bot has submitted this change and it was merged.
Change subject: Slightly more accurate results when filtering on dim/primary
......................................................................
Slightly more accurate results when filtering on dim/primary
The sort operation needs to be applied only to nested documents that match the
main query filter.
Test case:
Page A with :
- primary: 10.001|10.001
Page B with :
- primary: 10.002|10.002
- secondary: 10|10
Run a geosearch query limit=2 coord=10|10 primary=primary
Actual & excpected results:
- page A
- page B
Results are correct here because GeoData reorders results returned by elastic.
But running the same query with limit=1
Actual Results:
- page B
Expected results:
- page A
By using nested_filter we make sure that elastic with sort only subdocs
used by the main query.
Change-Id: I0ef8157db9a83e73e7814d94e01e990bfe08037f
---
M includes/api/ApiQueryGeoSearchElastic.php
1 file changed, 7 insertions(+), 3 deletions(-)
Approvals:
MaxSem: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/api/ApiQueryGeoSearchElastic.php
b/includes/api/ApiQueryGeoSearchElastic.php
index 608b3d0..4226e48 100644
--- a/includes/api/ApiQueryGeoSearchElastic.php
+++ b/includes/api/ApiQueryGeoSearchElastic.php
@@ -27,20 +27,21 @@
$namespaces = array_map( 'intval', $params['namespace'] );
$filter = new \Elastica\Query\BoolQuery();
+ $nestedPropsFilter = new \Elastica\Query\BoolQuery();
if ( $this->idToExclude ) {
$filter->addMustNot( new \Elastica\Query\Term( [ '_id'
=> $this->idToExclude ] ) );
}
// Only Earth is supported
- $filter->addFilter( new \Elastica\Query\Term( [
'coordinates.globe' => 'earth' ] ) );
+ $nestedPropsFilter->addFilter( new \Elastica\Query\Term( [
'coordinates.globe' => 'earth' ] ) );
if ( isset( $params['maxdim'] ) ) {
- $filter->addFilter( new \Elastica\Query\Range(
'coordinates.dim',
+ $nestedPropsFilter->addFilter( new
\Elastica\Query\Range( 'coordinates.dim',
[ 'to' => $params['maxdim'] ] ) );
}
$primary = $params['primary'];
if ( $primary !== 'all' ) {
- $filter->addFilter( new \Elastica\Query\Term( [
+ $nestedPropsFilter->addFilter( new
\Elastica\Query\Term( [
'coordinates.primary' => intval(
$primary === 'primary' )
] ) );
}
@@ -59,6 +60,8 @@
$distanceFilter->setOptimizeBbox( 'indexed' );
}
}
+
+ $filter->addFilter( $nestedPropsFilter );
$filter->addFilter( $distanceFilter );
$query = new \Elastica\Query();
@@ -81,6 +84,7 @@
$query->addSort( [
'_geo_distance' => [
'nested_path' => 'coordinates',
+ 'nested_filter' =>
$nestedPropsFilter->toArray(),
'coordinates.coord' => [
'lat' => $this->coord->lat,
'lon' => $this->coord->lon
--
To view, visit https://gerrit.wikimedia.org/r/297581
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0ef8157db9a83e73e7814d94e01e990bfe08037f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GeoData
Gerrit-Branch: master
Gerrit-Owner: DCausse <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits