jenkins-bot has submitted this change and it was merged. Change subject: Cleanup annotations and signatures in CirrusSearch\BuildDocument ......................................................................
Cleanup annotations and signatures in CirrusSearch\BuildDocument Bug: T132625 Change-Id: I60a99979a4daa734eba00963c81d7b6e961540b9 --- M includes/BuildDocument/RedirectsAndIncomingLinks.php M includes/BuildDocument/SuggestBuilder.php M includes/BuildDocument/SuggestScoring.php 3 files changed, 44 insertions(+), 23 deletions(-) Approvals: MaxSem: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/BuildDocument/RedirectsAndIncomingLinks.php b/includes/BuildDocument/RedirectsAndIncomingLinks.php index fb51505..60c45c4 100644 --- a/includes/BuildDocument/RedirectsAndIncomingLinks.php +++ b/includes/BuildDocument/RedirectsAndIncomingLinks.php @@ -5,7 +5,6 @@ use CirrusSearch\Connection; use CirrusSearch\ElasticsearchIntermediary; use Elastica\Filter\Terms; -use Elastica\Search; use Elastica\Query\Filtered; use Elastica\Query\MatchAll; use MediaWiki\Logger\LoggerFactory; @@ -32,12 +31,19 @@ */ class RedirectsAndIncomingLinks extends ElasticsearchIntermediary { /** - * @var static copy of this class kept during batches + * @var SplObjectStorage|null copy of this class kept during batches */ private static $externalLinks = null; - private $linkCountMultiSearch = null; - private $linkCountClosures = null; + /** + * @var \Elastica\Multi\Search + */ + private $linkCountMultiSearch; + + /** + * @var callable[] + */ + private $linkCountClosures = array(); public static function buildDocument( $doc, $title, Connection $conn ) { if ( self::$externalLinks === null ) { @@ -65,7 +71,6 @@ protected function __construct( Connection $conn ) { parent::__construct( $conn, null, null ); $this->linkCountMultiSearch = new \Elastica\Multi\Search( $conn->getClient() ); - $this->linkCountClosures = array(); } private function realBuildDocument( $doc, $title ) { @@ -135,17 +140,20 @@ /** * Build a Search that will count all pages that link to $titles. - * @param string $titles title in prefixedDBKey form - * @return Search that counts all pages that link to $titles + * @param string[] $titles title in prefixedDBKey form + * @return \Elastica\Search that counts all pages that link to $titles */ - private function buildCount( $titles ) { + private function buildCount( array $titles ) { $filter = new Terms( 'outgoing_link', $titles ); $filter->setCached( false ); // We're not going to be redoing this any time soon. $type = $this->connection->getPageType( wfWikiId() ); - $search = new Search( $type->getIndex()->getClient() ); + $search = new \Elastica\Search( $type->getIndex()->getClient() ); $search->addIndex( $type->getIndex() ); $search->addType( $type ); - $search->setOption( Search::OPTION_SEARCH_TYPE, Search::OPTION_SEARCH_TYPE_COUNT ); + $search->setOption( + \Elastica\Search::OPTION_SEARCH_TYPE, + \Elastica\Search::OPTION_SEARCH_TYPE_COUNT + ); $matchAll = new MatchAll(); $search->setQuery( new Filtered( $matchAll, $filter ) ); $search->getQuery()->addParam( 'stats', 'link_count' ); diff --git a/includes/BuildDocument/SuggestBuilder.php b/includes/BuildDocument/SuggestBuilder.php index 9588610..5179628 100644 --- a/includes/BuildDocument/SuggestBuilder.php +++ b/includes/BuildDocument/SuggestBuilder.php @@ -222,7 +222,7 @@ * Inspects the 'coordinates' index and return the first coordinates flagged as 'primary' * or the first coordinates if no primaries are found. * @param array $inputDoc the input doc - * @return array with 'lat' and 'lon' or null + * @return array|null with 'lat' and 'lon' or null */ public function findPrimaryCoordinates( $inputDoc ) { if ( !isset( $inputDoc['coordinates'] ) || !is_array( $inputDoc['coordinates'] ) ) { @@ -252,7 +252,7 @@ * @param array $title the title in 'text' and an array of similar redirects in 'variants' * @param array $location the geo coordinates or null if unavailable * @param int $score the weight of the suggestion - * @return array the suggestion document + * @return \Elastica\Document the suggestion document */ private function buildTitleSuggestion( $id, $title, $location, $score ) { $inputs = array( $this->prepareInput( $title['text'] ) ); @@ -260,7 +260,13 @@ $inputs[] = $this->prepareInput( $variant ); } $output = self::encodeTitleOutput( $id, $title['text'] ); - return $this->buildSuggestion( self::TITLE_SUGGESTION . $id, $output, $inputs, $location, $score ); + return $this->buildSuggestion( + self::TITLE_SUGGESTION . $id, + $output, + $inputs, + $location, + $score + ); } /** @@ -275,7 +281,7 @@ * @param string[] $redirects * @param array $location the geo coordinates or null if unavailable * @param int $score the weight of the suggestion - * @return array the suggestion document + * @return \Elastica\Document the suggestion document */ private function buildRedirectsSuggestion( $id, $redirects, $location, $score ) { $inputs = array(); @@ -290,11 +296,12 @@ /** * Builds a suggestion document. * + * @param string $id The document id * @param string $output the suggestion output - * @param string $inputs the suggestion inputs + * @param string[] $inputs the suggestion inputs * @param array $location the geo coordinates or null if unavailable * @param int $score the weight of the suggestion - * @return array a doc ready to be indexed in the completion suggester + * @return \Elastica\Document a doc ready to be indexed in the completion suggester */ private function buildSuggestion( $id, $output, $inputs, $location, $score ) { $doc = array( @@ -489,7 +496,7 @@ * type: either REDIRECT_SUGGESTION or TITLE_SUGGESTION * text (optional): if TITLE_SUGGESTION the Title text * @param string $output text value returned by a suggest query - * @return array mixed or null if the output is not properly encoded + * @return array|null mixed or null if the output is not properly encoded */ public static function decodeOutput( $output ) { if ( $output == null ) { @@ -522,7 +529,7 @@ } /** - * @return long the batchId + * @return int the batchId */ public function getBatchId() { return $this->batchId; diff --git a/includes/BuildDocument/SuggestScoring.php b/includes/BuildDocument/SuggestScoring.php index edfd649..2330b1e 100644 --- a/includes/BuildDocument/SuggestScoring.php +++ b/includes/BuildDocument/SuggestScoring.php @@ -49,7 +49,7 @@ * @param array $doc A document from the PAGE type * @return int the weight of the document */ - public function score( $doc ); + public function score( array $doc ); /** * The list of fields needed to compute the score. @@ -73,7 +73,7 @@ /** * {@inheritDoc} */ - public function score( $doc ) { + public function score( array $doc ) { return isset( $doc['incoming_links'] ) ? $doc['incoming_links'] : 0; } @@ -84,6 +84,9 @@ return array( 'incoming_links' ); } + /** + * @param int $maxDocs + */ public function setMaxDocs( $maxDocs ) {} } @@ -149,11 +152,11 @@ /** * {@inheritDoc} */ - public function score( $doc ) { + public function score( array $doc ) { return intval( $this->intermediateScore( $doc ) * self::SCORE_RANGE ); } - protected function intermediateScore( $doc ) { + protected function intermediateScore( array $doc ) { $incLinks = $this->scoreNormL2( isset( $doc['incoming_links'] ) ? $doc['incoming_links'] : 0, $this->incomingLinksNorm ); $pageSize = $this->scoreNormL2( isset( $doc['text_bytes'] ) ? $doc['text_bytes'] : 0, self::PAGE_SIZE_NORM ); $extLinks = $this->scoreNorm( isset( $doc['external_link'] ) ? count( $doc['external_link'] ) : 0, self::EXTERNAL_LINKS_NORM ); @@ -259,6 +262,9 @@ return array( 'incoming_links', 'external_link', 'text_bytes', 'heading', 'redirect', 'template' ); } + /** + * @param int $maxDocs + */ public function setMaxDocs( $maxDocs ) { $this->maxDocs = $maxDocs; // We normalize incoming links according to the size of the index @@ -289,7 +295,7 @@ return array_merge( parent::getRequiredFields(), array( 'popularity_score' ) ); } - public function score( $doc ) { + public function score( array $doc ) { $score = $this->intermediateScore( $doc ) * self::QSCORE_WEIGHT; $pop = isset( $doc['popularity_score'] ) ? $doc['popularity_score'] : 0; if ( $pop > self::POPULARITY_MAX ) { -- To view, visit https://gerrit.wikimedia.org/r/283354 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I60a99979a4daa734eba00963c81d7b6e961540b9 Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/CirrusSearch Gerrit-Branch: master Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: DCausse <dcau...@wikimedia.org> Gerrit-Reviewer: Gehel <gleder...@wikimedia.org> Gerrit-Reviewer: Manybubbles <never...@wikimedia.org> Gerrit-Reviewer: MaxSem <maxsem.w...@gmail.com> 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