jenkins-bot has submitted this change and it was merged.
Change subject: Use filtered query rather than results filtering
......................................................................
Use filtered query rather than results filtering
It isn't super clear from Elasticsearch's documenation but this is
supposed to be faster. The Elasticsearch documentation is being fixed
so we should switch as well.
Bug: 56723
Change-Id: I379dd0e429b7231854fdc52d37ed307c954eed2a
---
M includes/CirrusSearchSearcher.php
1 file changed, 26 insertions(+), 13 deletions(-)
Approvals:
Chad: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/CirrusSearchSearcher.php
b/includes/CirrusSearchSearcher.php
index fa12d76..b52b06e 100644
--- a/includes/CirrusSearchSearcher.php
+++ b/includes/CirrusSearchSearcher.php
@@ -53,6 +53,9 @@
private $resultsType;
// These fields are filled in by the particule search methods
+ /**
+ * @var \Elastica\Query\AbstractQuery|null main query. null defaults
to \Elastica\Query\MatchAll
+ */
private $query = null;
private $filters = array();
private $suggest = null;
@@ -341,9 +344,32 @@
if ( $this->resultsType === null ) {
$this->resultsType = new
CirrusSearchFullTextResultsType();
}
+ // Default null queries now so the rest of the method can
assume it is not null.
+ if ( $this->query === null ) {
+ $this->query = new \Elastica\Query\MatchAll();
+ }
$query = new Elastica\Query();
$query->setFields( $this->resultsType->getFields() );
+
+ if ( $this->namespaces ) {
+ $this->filters[] = new \Elastica\Filter\Terms(
'namespace', $this->namespaces );
+ }
+
+ // Wrap $this->query in a filtered query if there are filters.
+ $filterCount = count( $this->filters );
+ if ( $filterCount > 0 ) {
+ if ( $filterCount > 1 ) {
+ $filter = new \Elastica\Filter\Bool();
+ foreach ( $this->filters as $must ) {
+ $filter->addMust( $must );
+ }
+ } else {
+ $filter = $this->filters[ 0 ];
+ }
+ $this->query = new \Elastica\Query\Filtered(
$this->query, $filter );
+ }
+
$query->setQuery( self::boostQuery( $this->query ) );
$highlight = $this->resultsType->getHighlightingConfiguration();
@@ -364,19 +390,6 @@
$this->rescore[ 'query' ][ 'rescore_query' ] =
self::boostQuery( $this->rescore[ 'query' ][
'rescore_query' ] )->toArray();
$query->setParam( 'rescore', $this->rescore );
- }
-
- if ( $this->namespaces ) {
- $this->filters[] = new \Elastica\Filter\Terms(
'namespace', $this->namespaces );
- }
- if ( count( $this->filters ) > 1 ) {
- $mainFilter = new \Elastica\Filter\Bool();
- foreach ( $this->filters as $filter ) {
- $mainFilter->addMust( $filter );
- }
- $query->setFilter( $mainFilter );
- } else if ( count( $this->filters ) === 1 ) {
- $query->setFilter( $this->filters[0] );
}
$queryOptions = array();
--
To view, visit https://gerrit.wikimedia.org/r/94387
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I379dd0e429b7231854fdc52d37ed307c954eed2a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Manybubbles <[email protected]>
Gerrit-Reviewer: Chad <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits