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

Change subject: Clean up empty result set scenario
......................................................................


Clean up empty result set scenario

Provide an empty result set wrapper that allows us to still
use our ResultSet instead of core's SearchResultSet.

While we're here, clean up usage of $containedSyntax to use
the parent's protected implementation instead of DIY.

Couple of doc fixes and such as well.

Bug: T104189
Change-Id: I4e7225b6c9a52d1c40ea80abd8a0fe352b7a35b9
---
M autoload.php
M includes/CirrusSearch.php
A includes/Search/EmptyResultSet.php
M includes/Search/ResultSet.php
M includes/Searcher.php
5 files changed, 59 insertions(+), 13 deletions(-)

Approvals:
  Manybubbles: 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 0297c6b..956583c 100644
--- a/autoload.php
+++ b/autoload.php
@@ -63,6 +63,7 @@
        'CirrusSearch\\Sanity\\PrintingRemediator' => __DIR__ . 
'/includes/Sanity/Remediator.php',
        'CirrusSearch\\Sanity\\QueueingRemediator' => __DIR__ . 
'/includes/Sanity/QueueingRemediator.php',
        'CirrusSearch\\Sanity\\Remediator' => __DIR__ . 
'/includes/Sanity/Remediator.php',
+       'CirrusSearch\\Search\\EmptyResultSet' => __DIR__ . 
'/includes/Search/EmptyResultSet.php',
        'CirrusSearch\\Search\\Escaper' => __DIR__ . 
'/includes/Search/Escaper.php',
        'CirrusSearch\\Search\\EscaperTest' => __DIR__ . 
'/tests/unit/Search/EscaperTest.php',
        'CirrusSearch\\Search\\FancyTitleResultsType' => __DIR__ . 
'/includes/Search/ResultsType.php',
diff --git a/includes/CirrusSearch.php b/includes/CirrusSearch.php
index f16c47e..d3b977f 100644
--- a/includes/CirrusSearch.php
+++ b/includes/CirrusSearch.php
@@ -1,6 +1,7 @@
 <?php
 
 use CirrusSearch\InterwikiSearcher;
+use CirrusSearch\Search\EmptyResultSet;
 use CirrusSearch\Search\FullTextResultsType;
 use CirrusSearch\Searcher;
 
@@ -200,7 +201,7 @@
                if ( count( $titles ) ) {
                        return $searcher->moreLikeTheseArticles( $titles, 
$options );
                }
-               return Status::newGood( new SearchResultSet() /* empty */ );
+               return Status::newGood( new EmptyResultSet( true ) );
        }
        /**
         * Merge the prefix into the query (if any).
diff --git a/includes/Search/EmptyResultSet.php 
b/includes/Search/EmptyResultSet.php
new file mode 100644
index 0000000..c7c7f48
--- /dev/null
+++ b/includes/Search/EmptyResultSet.php
@@ -0,0 +1,30 @@
+<?php
+namespace CirrusSearch\Search;
+
+/**
+ * An empty set of results from Elasticsearch
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+class EmptyResultSet extends ResultSet {
+       /**
+        * Constructor.
+        * @param bool $containedSyntax Did the search query contain advanced 
syntax
+        */
+       public function __construct( $containedSyntax = false ) {
+               $this->containedSyntax = $containedSyntax;
+       }
+}
diff --git a/includes/Search/ResultSet.php b/includes/Search/ResultSet.php
index 40dcef2..8285bcd 100644
--- a/includes/Search/ResultSet.php
+++ b/includes/Search/ResultSet.php
@@ -24,13 +24,32 @@
  * http://www.gnu.org/copyleft/gpl.html
  */
 class ResultSet extends SearchResultSet {
-       private $result, $hits, $totalHits, $suggestionQuery, 
$suggestionSnippet;
-       private $searchContainedSyntax;
-       private $interwikiPrefix, $interwikiResults;
+       /**
+        * Number of hits in this result set, and number of total hits found by
+        * the query
+        * @var int
+        */
+       private $hits, $totalHits = 0;
+
+       /**
+        * @var string
+        */
+       private $suggestionQuery, $suggestionSnippet = '';
+
+       /**
+        * Result wrapper
+        */
+       private $result;
+
+       /**
+        * An array of ResultSets for various interwiki searches
+        * @var array
+        */
+       private $interwikiResults = array();
 
        public function __construct( $suggestPrefixes, $suggestSuffixes, $res, 
$searchContainedSyntax, $interwiki = '' ) {
                $this->result = $res;
-               $this->searchContainedSyntax = $searchContainedSyntax;
+               $this->containedSyntax = $searchContainedSyntax;
                $this->hits = $res->count();
                $this->totalHits = $res->getTotalHits();
                $this->interwikiPrefix = $interwiki;
@@ -159,9 +178,5 @@
 
        public function getInterwikiResults() {
                return $this->interwikiResults;
-       }
-
-       public function searchContainedSyntax() {
-               return $this->searchContainedSyntax;
        }
 }
diff --git a/includes/Searcher.php b/includes/Searcher.php
index 5586ebf..3ec2749 100644
--- a/includes/Searcher.php
+++ b/includes/Searcher.php
@@ -12,7 +12,6 @@
 use \Language;
 use \MWNamespace;
 use \RequestContext;
-use \SearchResultSet;
 use \Status;
 use \Title;
 use \UsageException;
@@ -569,7 +568,7 @@
                        }
                );
                if ( $isEmptyQuery ) {
-                       return Status::newGood( new SearchResultSet( true ) );
+                       return Status::newGood( new EmptyResultSet( true ) );
                }
                $this->filters = $filters;
                $this->notFilters = $notFilters;
@@ -820,7 +819,7 @@
                // This can happen if the user override this setting with field 
names that
                // are not allowed in $wgCirrusSearchMoreLikeThisAllowedFields 
(see Hooks.php)
                if( !$wgCirrusSearchMoreLikeThisFields ) {
-                       return Status::newGood( new SearchResultSet() /* empty 
*/ );
+                       return Status::newGood( new EmptyResultSet() );
                }
 
                $this->query = new \Elastica\Query\MoreLikeThis();
@@ -844,7 +843,7 @@
                        $found = $found->getValue();
                        if ( count( $found ) === 0 ) {
                                // If none of the pages are in the index we 
can't find articles like them
-                               return Status::newGood( new SearchResultSet() 
/* empty */ );
+                               return Status::newGood( new EmptyResultSet() );
                        }
                        foreach ( $found as $foundArticle ) {
                                $text[] = $foundArticle->text;

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I4e7225b6c9a52d1c40ea80abd8a0fe352b7a35b9
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Chad <ch...@wikimedia.org>
Gerrit-Reviewer: DCausse <dcau...@wikimedia.org>
Gerrit-Reviewer: EBernhardson <ebernhard...@wikimedia.org>
Gerrit-Reviewer: Manybubbles <never...@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