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

Change subject: Annotate SearchResult and related classes
......................................................................


Annotate SearchResult and related classes

Bug: T132625
Change-Id: Ifcf08869717ce9b9bb169ea2e52bb99938565e5b
---
M includes/Search/Result.php
M includes/Search/ResultSet.php
M includes/Search/ResultsType.php
3 files changed, 157 insertions(+), 34 deletions(-)

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



diff --git a/includes/Search/Result.php b/includes/Search/Result.php
index 4908f5b..e96f1eb 100644
--- a/includes/Search/Result.php
+++ b/includes/Search/Result.php
@@ -29,17 +29,37 @@
  * http://www.gnu.org/copyleft/gpl.html
  */
 class Result extends SearchResult {
+       /** @var string */
        private $titleSnippet = '';
-       private $redirectTitle = null, $redirectSnipppet = '';
-       private $sectionTitle = null, $sectionSnippet = '';
+       /** @var Title|null */
+       private $redirectTitle = null;
+       /** @var string */
+       private $redirectSnipppet = '';
+       /** @var Title|null */
+       private $sectionTitle = null;
+       /** @var string */
+       private $sectionSnippet = '';
+       /** @var string */
        private $categorySnippet = '';
-       private $textSnippet = '', $isFileMatch = false;
-       private $interwiki = '', $interwikiNamespace = '';
+       /** @var string */
+       private $textSnippet;
+       /** @var bool */
+       private $isFileMatch = false;
+       /* @var string */
+       private $interwiki = '';
+       /** @var string */
+       private $interwikiNamespace = '';
+       /** @var int */
        private $wordCount;
+       /** @var int */
        private $byteSize;
+       /** @var string */
        private $timestamp;
+       /** @var string */
        private $docId;
+       /** @var float */
        private $score;
+       /** @var array */
        private $explanation;
 
        /**
@@ -47,7 +67,7 @@
         * @param \Elastica\ResultSet $results containing all search results
         * @param \Elastica\Result $result containing the given search result
         * @param string $interwiki Interwiki prefix, if any
-        * @param \Elastic\Result $result containing information about the 
result this class should represent
+        * @param \Elastica\Result $result containing information about the 
result this class should represent
         */
        public function __construct( $results, $result, $interwiki = '' ) {
                if ( $interwiki ) {
@@ -178,8 +198,8 @@
        /**
         * Build the redirect title from the highlighted redirect snippet.
         * @param string $snippet Highlighted redirect snippet
-        * @param array[] $redirects Array of redirects stored as arrays with 
'title' and 'namespace' keys
-        * @return Title object representing the redirect
+        * @param array[]|null $redirects Array of redirects stored as arrays 
with 'title' and 'namespace' keys
+        * @return Title|null object representing the redirect
         */
        private function findRedirectTitle( $snippet, $redirects ) {
                $title = $this->stripHighlighting( $snippet );
@@ -261,7 +281,8 @@
        }
 
        /**
-        * @return Title|null
+        * @param array
+        * @return string|null
         */
        public function getTextSnippet( $terms ) {
                return $this->textSnippet;
@@ -331,7 +352,7 @@
        }
 
        /**
-        * @return int
+        * @return string
         */
        public function getDocId() {
                return $this->docId;
diff --git a/includes/Search/ResultSet.php b/includes/Search/ResultSet.php
index d0b5880..be78d67 100644
--- a/includes/Search/ResultSet.php
+++ b/includes/Search/ResultSet.php
@@ -28,13 +28,65 @@
         * @var \Elastica\ResultSet
         */
        private $result;
-       private $hits, $totalHits, $suggestionQuery, $suggestionSnippet;
+
+       /**
+        * @var int
+        */
+       private $hits;
+
+       /**
+        * @var int
+        */
+       private $totalHits;
+
+       /**
+        * @var string|null
+        */
+       private $suggestionQuery;
+
+       /**
+        * @var string
+        */
+       private $suggestionSnippet;
+
+       /**
+        * @var bool
+        */
        private $searchContainedSyntax;
-       private $interwikiPrefix,$interwikiResults;
+
+       /**
+        * @var string
+        */
+       private $interwikiPrefix;
+
+       /**
+        * @var array
+        */
+       private $interwikiResults = array();
+
+       /**
+        * @var string|null
+        */
        private $rewrittenQuery;
+
+       /**
+        * @var string|null
+        */
+       private $rewrittenQuerySnippet;
+
+       /**
+        * @var \Iterator|null
+        */
        private $swappedResultIter;
 
-       public function __construct( $suggestPrefixes, $suggestSuffixes, $res, 
$searchContainedSyntax, $interwiki = '' ) {
+       /**
+        * @param string[] $suggestPrefixes
+        * @param string[] $suggestSuffixes
+        * @param \Elastica\ResultSet $res
+        * @param bool $searchContainedSyntax
+        * @param string $interwiki
+        */
+       public function __construct( array $suggestPrefixes, array 
$suggestSuffixes, \Elastica\ResultSet $res, $searchContainedSyntax, $interwiki 
= '' ) {
                $this->result = $res;
                $this->searchContainedSyntax = $searchContainedSyntax;
                $this->hits = $res->count();
@@ -227,8 +279,8 @@
        }
 
        /**
-        * @param Result $res
-        * @param string $type
+        * @param ResultSet $res
+        * @param int $type One of SearchResultSet::* constants
         * @param string $interwiki
         */
        public function addInterwikiResults( $res, $type, $interwiki ) {
@@ -237,7 +289,7 @@
 
        /**
         * @param string $type
-        * @return Result[]
+        * @return SearchResultSet[]
         */
        public function getInterwikiResults( $type = 
SearchResultSet::SECONDARY_RESULTS ) {
                return isset($this->interwikiResults[$type]) ? 
$this->interwikiResults[$type] : array();
diff --git a/includes/Search/ResultsType.php b/includes/Search/ResultsType.php
index d247fd2..b370e69 100644
--- a/includes/Search/ResultsType.php
+++ b/includes/Search/ResultsType.php
@@ -40,11 +40,19 @@
         * Get the highlighting configuration.
         * @param array $highlightSource configuration for how to highlight the 
source.
         *  Empty if source should be ignored.
-        * @return array highlighting configuration for elasticsearch
+        * @return array|null highlighting configuration for elasticsearch
         */
-       function getHighlightingConfiguration( $highlightSource );
-       function transformElasticsearchResult( $suggestPrefixes, 
$suggestSuffixes,
-               $result, $searchContainedSyntax );
+       function getHighlightingConfiguration( array $highlightSource );
+
+       /**
+        * @param string[] $suggestPrefixes
+        * @param string[] $suggestSuffixes
+        * @param \Elastica\ResultSet $result
+        * @param bool $searchContainedSyntax
+        * @return mixed Set of search results, the types of which vary by 
implementation.
+        */
+       function transformElasticsearchResult( array $suggestPrefixes, array 
$suggestSuffixes,
+               \Elastica\ResultSet $result, $searchContainedSyntax );
 }
 
 /**
@@ -59,12 +67,23 @@
                return false;
        }
 
-       public function getHighlightingConfiguration( $highlightSource ) {
-               return false;
+       /**
+        * @param array $highlightSource
+        * @return array|null
+        */
+       public function getHighlightingConfiguration( array $highlightSource ) {
+               return null;
        }
 
-       public function transformElasticsearchResult( $suggestPrefixes, 
$suggestSuffixes,
-               $resultSet, $searchContainedSyntax ) {
+       /**
+        * @param string[] $suggestPrefixes
+        * @param string[] $suggestSuffixes
+        * @param \Elastica\ResultSet $resultSet
+        * @param bool $searchContainedSyntax
+        * @return array
+        */
+       public function transformElasticsearchResult( array $suggestPrefixes, 
array $suggestSuffixes,
+               \Elastica\ResultSet $resultSet, $searchContainedSyntax ) {
                $results = array();
                foreach( $resultSet->getResults() as $r ) {
                        $results[] = Title::makeTitle( $r->namespace, $r->title 
);
@@ -88,7 +107,11 @@
                $this->matchedAnalyzer = $matchedAnalyzer;
        }
 
-       public function getHighlightingConfiguration( $highlightSource ) {
+       /**
+        * @param array $highlightSource
+        * @return array|null
+        */
+       public function getHighlightingConfiguration( array $highlightSource ) {
                global $wgCirrusSearchUseExperimentalHighlighter;
 
                if ( $wgCirrusSearchUseExperimentalHighlighter ) {
@@ -135,12 +158,16 @@
 
        /**
         * Convert the results to titles.
+        * @param string[] $suggestPrefixes
+        * @param string[] $suggestSuffixes
+        * @param \Elastica\ResultSet $resultSet
+        * @param bool $searchContainedSyntax
         * @return array[] Array of arrays, each with optional keys:
         *   titleMatch => a title if the title matched
         *   redirectMatches => an array of redirect matches, one per matched 
redirect
         */
-       public function transformElasticsearchResult( $suggestPrefixes, 
$suggestSuffixes,
-                       $resultSet, $searchContainedSyntax ) {
+       public function transformElasticsearchResult( array $suggestPrefixes, 
array $suggestSuffixes,
+                       \Elastica\ResultSet $resultSet, $searchContainedSyntax 
) {
                $results = array();
                foreach( $resultSet->getResults() as $r ) {
                        $title = Title::makeTitle( $r->namespace, $r->title );
@@ -240,9 +267,11 @@
         * Get just one fragment from the text because that is all we will 
display.
         * Get one fragment from redirect title and heading each or else they
         * won't be sorted by score.
-        * @return array of highlighting configuration
+        *
+        * @param array $highlightSource
+        * @return array|null of highlighting configuration
         */
-       public function getHighlightingConfiguration( $highlightSource ) {
+       public function getHighlightingConfiguration( array $highlightSource ) {
                global $wgCirrusSearchUseExperimentalHighlighter,
                        $wgCirrusSearchFragmentSize;
 
@@ -352,8 +381,15 @@
                return $config;
        }
 
-       public function transformElasticsearchResult( $suggestPrefixes, 
$suggestSuffixes,
-                       $result, $searchContainedSyntax ) {
+       /**
+        * @param string[] $suggestPrefixes
+        * @param string[] $suggestSuffixes
+        * @param ResultSet $result
+        * @param bool $searchContainedSyntax
+        * @return ResultSet
+        */
+       public function transformElasticsearchResult( array $suggestPrefixes, 
array $suggestSuffixes,
+                       \Elastica\ResultSet $result, $searchContainedSyntax ) {
                return new ResultSet( $suggestPrefixes, $suggestSuffixes, 
$result, $searchContainedSyntax, $this->prefix );
        }
 
@@ -415,8 +451,15 @@
                return false;
        }
 
-       public function transformElasticsearchResult( $suggestPrefixes, 
$suggestSuffixes,
-               $resultSet, $searchContainedSyntax ) {
+       /**
+        * @param string[] $suggestPrefixes
+        * @param string[] $suggestSuffixes
+        * @param \Elastica\ResultSet $resultSet
+        * @param bool $searchContainedSyntax
+        * @return string[]
+        */
+       public function transformElasticsearchResult( array $suggestPrefixes, 
array $suggestSuffixes,
+               \Elastica\ResultSet $resultSet, $searchContainedSyntax ) {
                $results = array();
                foreach( $resultSet->getResults() as $r ) {
                        $results[] = $r->getId();
@@ -438,11 +481,18 @@
                $this->prefix = $interwiki;
        }
 
-       public function transformElasticsearchResult( $suggestPrefixes, 
$suggestSuffixes, $result, $searchContainedSyntax ) {
+       /**
+        * @param string[] $suggestPrefixes
+        * @param string[] $suggestSuffixes
+        * @param \Elastica\ResultSet $result
+        * @param bool $searchContainedSyntax
+        * @return ResultSet
+        */
+       public function transformElasticsearchResult( array $suggestPrefixes, 
array $suggestSuffixes, \Elastica\ResultSet $result, $searchContainedSyntax ) {
                return new ResultSet( $suggestPrefixes, $suggestSuffixes, 
$result, $searchContainedSyntax, $this->prefix );
        }
 
-       public function getHighlightingConfiguration( $highlightSource ) {
+       public function getHighlightingConfiguration( array $highlightSource ) {
                return null;
        }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ifcf08869717ce9b9bb169ea2e52bb99938565e5b
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org>
Gerrit-Reviewer: Cindy-the-browser-test-bot <bernhardsone...@gmail.com>
Gerrit-Reviewer: DCausse <dcau...@wikimedia.org>
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: jenkins-bot <>

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

Reply via email to