Smalyshev has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/239444

Change subject: [WIP] Displaying search results for multiple wikis
......................................................................

[WIP] Displaying search results for multiple wikis

Bug: T112349
Change-Id: I0d0efacf3066b3b5fe0bfcb058dd0b0f9988ccae
---
M includes/CirrusSearch.php
M includes/Search/ResultSet.php
2 files changed, 35 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch 
refs/changes/44/239444/1

diff --git a/includes/CirrusSearch.php b/includes/CirrusSearch.php
index a1c1202..2f60676 100644
--- a/includes/CirrusSearch.php
+++ b/includes/CirrusSearch.php
@@ -146,7 +146,9 @@
                                }
                                if ( $config ) {
                                        $matches = $this->searchTextReal( 
$term, $config );
-                                       return $matches;
+                                       if( $matches instanceof ResultSet && 
$matches->numRows() > 0 ) {
+                                               
$zeroResult->addInterwikiResults( $matches, SearchResultSet::INLINE_RESULTS, 
$altWiki[1] );
+                                       }
                                }
                        }
                        // Don't have any other options yet.
@@ -270,7 +272,7 @@
                                $iwSearch = new InterwikiSearcher( 
$this->namespaces, $user, $index, $interwiki );
                                $interwikiResult = 
$iwSearch->getInterwikiResults( $term );
                                if ( $interwikiResult ) {
-                                       
$status->getValue()->addInterwikiResults( $interwikiResult );
+                                       
$status->getValue()->addInterwikiResults( $interwikiResult, 
SearchResultSet::SIDEBAR_RESULTS, $interwiki );
                                }
                        }
                }
diff --git a/includes/Search/ResultSet.php b/includes/Search/ResultSet.php
index 401aaa5..3fba84c 100644
--- a/includes/Search/ResultSet.php
+++ b/includes/Search/ResultSet.php
@@ -24,7 +24,11 @@
  * http://www.gnu.org/copyleft/gpl.html
  */
 class ResultSet extends SearchResultSet {
-       private $result, $hits, $totalHits, $suggestionQuery, 
$suggestionSnippet;
+       /**
+        * @var Elastica\ResultSet
+        */
+       private $result;
+       private $hits, $totalHits, $suggestionQuery, $suggestionSnippet;
        private $searchContainedSyntax;
        private $interwikiPrefix,$interwikiResults;
        private $rewrittenQuery;
@@ -35,7 +39,7 @@
                $this->hits = $res->count();
                $this->totalHits = $res->getTotalHits();
                $this->interwikiPrefix = $interwiki;
-               $this->preCacheContainedTitles();
+               $this->preCacheContainedTitles( $this->result );
                $suggestion = $this->findSuggestion();
                if ( $suggestion && ! 
$this->resultContainsFullyHighlightedMatch() ) {
                        $this->suggestionQuery = $suggestion[ 'text' ];
@@ -55,6 +59,14 @@
                }
        }
 
+       public function addMoreResults ($res, $interwiki = '') {
+               $this->hits += $res->count();
+               $this->totalHits += $res->getTotalHits();
+               if( !$interwiki ) {
+                       $this->preCacheContainedTitles( $res );
+               }
+       }
+
        /**
         * @return bool True when rewriting this query is allowed
         */
@@ -62,11 +74,9 @@
                if ( $this->numRows() > 0 || $this->searchContainedSyntax() ) {
                        return false;
                }
-               if ( $this->interwikiResults !== null ) {
-                       foreach ( $this->interwikiResults as $resultSet ) {
-                               if ( $resultSet->numRows() > 0 ) {
-                                       return false;
-                               }
+               foreach ( $this->getInterwikiResults( self::SIDEBAR_RESULTS ) 
as $resultSet ) {
+                       if ( $resultSet->numRows() > 0 ) {
+                               return false;
                        }
                }
                return true;
@@ -96,7 +106,7 @@
         * @return string $suggestion with html escaped _except_ highlighting 
pre and post tags
         */
        private function escapeHighlightedSuggestion( $suggestion ) {
-               static $suggestionHighlightPreEscaped = null, 
+               static $suggestionHighlightPreEscaped = null,
                        $suggestionHighlightPostEscaped = null;
                if ( $suggestionHighlightPreEscaped === null ) {
                        $suggestionHighlightPreEscaped =
@@ -127,13 +137,13 @@
         * Result::isMissingRevision() don't trigger a query for each and
         * every search result.
         */
-       private function preCacheContainedTitles() {
+       private function preCacheContainedTitles( $resultSet ) {
                // We can only pull in information about the local wiki
-               if ( $this->interwikiPrefix !== '' ) {
-                       return;
-               }
+               if ( $this->interwikiPrefix !== '' ) {
+                       return;
+               }
                $lb = new LinkBatch;
-               foreach ( $this->result->getResults() as $result ) {
+               foreach ( $resultSet->getResults() as $result ) {
                        $lb->add( $result->namespace, $result->title );
                }
                if ( !$lb->isEmpty() ) {
@@ -171,12 +181,16 @@
                return false;
        }
 
-       public function addInterwikiResults( $res ) {
-               $this->interwikiResults[] = $res;
+       public function addInterwikiResults( $res, $type, $interwiki ) {
+               $this->interwikiResults[$type][$interwiki] = $res;
        }
 
-       public function getInterwikiResults() {
-               return $this->interwikiResults;
+       public function getInterwikiResults( $type = self::SIDEBAR_RESULTS ) {
+               return isset($this->interwikiResults[$type])? 
$this->interwikiResults[$type] : array();
+       }
+
+       function hasInterwikiResults( $type = self::SIDEBAR_RESULTS ) {
+               return !empty($this->interwikiResults[$type]);
        }
 
        public function searchContainedSyntax() {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0d0efacf3066b3b5fe0bfcb058dd0b0f9988ccae
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Smalyshev <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to