jenkins-bot has submitted this change and it was merged.

Change subject: Properly pass query options when using multi search
......................................................................


Properly pass query options when using multi search

This looks like a bug in Elastica where all the search options
(timeout, terminate_after...) are passed in the header section of the
multisearch syntax.  Only few options need to go into the header
others must be passed in the search request body otherwise they are
inneffective.
This patch is backport of a PR suggested to ruflin.

Change-Id: I7a1e818c7ead0188516771f1f4ba82d2937cb8cc
---
M autoload.php
M includes/BuildDocument/RedirectsAndIncomingLinks.php
A includes/Elastica/MultiSearch.php
M includes/OtherIndexes.php
M includes/Searcher.php
M maintenance/updateSuggesterIndex.php
6 files changed, 42 insertions(+), 5 deletions(-)

Approvals:
  Cindy-the-browser-test-bot: Looks good to me, but someone else must approve
  EBernhardson: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/autoload.php b/autoload.php
index 4f493e9..bef7cd0 100644
--- a/autoload.php
+++ b/autoload.php
@@ -38,6 +38,7 @@
        'CirrusSearch\\DataSender' => __DIR__ . '/includes/DataSender.php',
        'CirrusSearch\\Dump' => __DIR__ . '/includes/Dump.php',
        'CirrusSearch\\ElasticaErrorHandler' => __DIR__ . 
'/includes/ElasticaErrorHandler.php',
+       'CirrusSearch\\Elastica\\MultiSearch' => __DIR__ . 
'/includes/Elastica/MultiSearch.php',
        'CirrusSearch\\Elastica\\PooledHttp' => __DIR__ . 
'/includes/Elastica/PooledHttp.php',
        'CirrusSearch\\Elastica\\PooledHttps' => __DIR__ . 
'/includes/Elastica/PooledHttps.php',
        'CirrusSearch\\ElasticsearchIntermediary' => __DIR__ . 
'/includes/ElasticsearchIntermediary.php',
diff --git a/includes/BuildDocument/RedirectsAndIncomingLinks.php 
b/includes/BuildDocument/RedirectsAndIncomingLinks.php
index 80a4ead..0c963f8 100644
--- a/includes/BuildDocument/RedirectsAndIncomingLinks.php
+++ b/includes/BuildDocument/RedirectsAndIncomingLinks.php
@@ -6,6 +6,7 @@
 use CirrusSearch\SearchConfig;
 use CirrusSearch\SearchRequestLog;
 use CirrusSearch\Connection;
+use CirrusSearch\Elastica\MultiSearch as MultiSearch;
 use Elastica\Query\BoolQuery;
 use Elastica\Query\Terms;
 use MediaWiki\Logger\LoggerFactory;
@@ -45,7 +46,7 @@
        private $config;
 
        /**
-        * @var \Elastica\Multi\Search
+        * @var MultiSearch
         */
        private $linkCountMultiSearch;
 
@@ -95,7 +96,7 @@
        protected function __construct( SearchConfig $config, Connection $conn 
) {
                parent::__construct( $conn, null, 0 );
                $this->config = $config;
-               $this->linkCountMultiSearch = new \Elastica\Multi\Search( 
$conn->getClient() );
+               $this->linkCountMultiSearch = new MultiSearch( 
$conn->getClient() );
        }
 
        private function realBuildDocument( \Elastica\Document $doc, Title 
$title ) {
diff --git a/includes/Elastica/MultiSearch.php 
b/includes/Elastica/MultiSearch.php
new file mode 100644
index 0000000..070a600
--- /dev/null
+++ b/includes/Elastica/MultiSearch.php
@@ -0,0 +1,32 @@
+<?php
+
+namespace CirrusSearch\Elastica;
+
+/**
+ * backport for https://github.com/ruflin/Elastica/pull/1224
+ */
+class MultiSearch extends \Elastica\Multi\Search {
+       /**
+        * @param \Elastica\Search $search
+        *
+        * @return string
+        */
+       protected function _getSearchData(\Elastica\Search $search) {
+               $header = $this->_getSearchDataHeader($search);
+               $header = (empty($header)) ? new \stdClass() : $header;
+               $query = $search->getQuery();
+               $toKeep = [
+                       'index' => true,
+                       'types' => true,
+                       'search_type' => true,
+                       'routing' => true,
+                       'preference' => true,
+               ];
+               $queryOptions = array_diff_key( $header, $toKeep );
+               $actualHeader = array_intersect_key( $header, $toKeep );;
+               $data = \Elastica\JSON::stringify($actualHeader)."\n";
+               $queryBody = $query->toArray() + $queryOptions;
+               $data .= \Elastica\JSON::stringify($queryBody)."\n";
+               return $data;
+       }
+}
diff --git a/includes/OtherIndexes.php b/includes/OtherIndexes.php
index 73ec5e7..188c02b 100644
--- a/includes/OtherIndexes.php
+++ b/includes/OtherIndexes.php
@@ -3,6 +3,7 @@
 namespace CirrusSearch;
 
 use MediaWiki\Logger\LoggerFactory;
+use CirrusSearch\Elastica\MultiSearch as MultiSearch;
 use Title;
 
 /**
@@ -84,7 +85,7 @@
                $updates = [];
 
                // Build multisearch to find ids to update
-               $findIdsMultiSearch = new \Elastica\Multi\Search( 
$this->connection->getClient() );
+               $findIdsMultiSearch = new MultiSearch( 
$this->connection->getClient() );
                $findIdsClosures = [];
                foreach ( $titles as $title ) {
                        foreach ( OtherIndexes::getExternalIndexes( $title ) as 
$otherIndex ) {
diff --git a/includes/Searcher.php b/includes/Searcher.php
index c44b4dd..915cb83 100644
--- a/includes/Searcher.php
+++ b/includes/Searcher.php
@@ -7,6 +7,7 @@
 use CirrusSearch\Search\RescoreBuilder;
 use CirrusSearch\Search\SearchContext;
 use CirrusSearch\Query\FullTextQueryBuilder;
+use CirrusSearch\Elastica\MultiSearch as MultiSearch;
 use Language;
 use MediaWiki\Logger\LoggerFactory;
 use MediaWiki\MediaWikiServices;
@@ -643,7 +644,7 @@
                // Similar to indexing support only the bulk code path, rather 
than
                // single and bulk. The extra overhead should be minimal, and 
the
                // reduced complexity is welcomed.
-               $search = new \Elastica\Multi\Search( 
$this->connection->getClient() );
+               $search = new MultiSearch( $this->connection->getClient() );
                $search->addSearches( $searches );
 
                $this->connection->setTimeout( $this->getTimeout() );
diff --git a/maintenance/updateSuggesterIndex.php 
b/maintenance/updateSuggesterIndex.php
index acb550c..1b99aa2 100644
--- a/maintenance/updateSuggesterIndex.php
+++ b/maintenance/updateSuggesterIndex.php
@@ -13,6 +13,7 @@
 use CirrusSearch\BuildDocument\Completion\SuggestScoringMethod;
 use CirrusSearch\Maintenance\Validators\AnalyzersValidator;
 use CirrusSearch\SearchConfig;
+use CirrusSearch\Elastica\MultiSearch as MultiSearch;
 use Elastica;
 use Elastica\Index;
 use Elastica\Query;
@@ -536,7 +537,7 @@
                // Run a first query to count the number of docs.
                // This is needed for the scoring methods that need
                // to normalize values against wiki size.
-               $mSearch = new \Elastica\Multi\Search( $this->getClient() );
+               $mSearch = new MultiSearch( $this->getClient() );
                foreach ( $countIndices as $sourceIndexType ) {
                        $search = new \Elastica\Search( $this->getClient() );
                        $search->addIndex( $this->getConnection()->getIndex( 
$this->indexBaseName, $sourceIndexType ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/324690
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I7a1e818c7ead0188516771f1f4ba82d2937cb8cc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: DCausse <dcau...@wikimedia.org>
Gerrit-Reviewer: Cindy-the-browser-test-bot <bernhardsone...@gmail.com>
Gerrit-Reviewer: EBernhardson <ebernhard...@wikimedia.org>
Gerrit-Reviewer: Gehel <gleder...@wikimedia.org>
Gerrit-Reviewer: Manybubbles <never...@wikimedia.org>
Gerrit-Reviewer: Smalyshev <smalys...@wikimedia.org>
Gerrit-Reviewer: Tjones <tjo...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to