MaxSem has uploaded a new change for review. https://gerrit.wikimedia.org/r/155622
Change subject: Preserve order for list=prefixsearch when used as a generator ...................................................................... Preserve order for list=prefixsearch when used as a generator Because its order is usually user-facing, protect it from e.g. MySQL implicitly sorting results by primary index. This problem currently affects mobile, Trello card: https://trello.com/c/J52fOPCY/17-5-better-search-results Change-Id: Ibc6fe16f13b0fa341ee4962ccfaa3366b6646ed1 --- M includes/api/ApiPageSet.php M includes/api/ApiQueryPrefixSearch.php 2 files changed, 65 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/22/155622/1 diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index 0f26467..a3577f1 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -622,6 +622,70 @@ } /** + * Populate this PageSet from a list of Titles that are known to: + * - be normalized AND + * - be already known to LinkCache AND MAY + * - be in an order that needs to be preserved + * + * @param array[Title] $titles Array of Title objects + */ + public function populateFromKnownTitles( array $titles ) { + $this->profileIn(); + + $ids = array(); + $usernames = array(); + /** @var Title $title */ + foreach ( $titles as $title ) { + $pageId = $title->getArticleID(); + if ( $pageId ) { + $ids[] = $pageId; + $this->mGoodTitles[$pageId] = $title; + if ( $this->mResolveRedirects && $title->isRedirect() ) { + $this->mPendingRedirectIDs[$pageId] = $title; + } + if ( MWNamespace::hasGenderDistinction( $title->getNamespace() ) ) { + $usernames[] = $title; + } + } else { + $pageId = $this->mFakePageId; + $this->mFakePageId--; + if ( $title->getNamespace() < 0 ) { + $this->mSpecialTitles[$pageId] = $title; + } elseif ( $title->isExternal() ) { + $this->mInterwikiTitles[$pageId] = $title; + } else { + $this->mMissingTitles[$pageId] = $title; + } + } + $this->mTitles[] = $title; + $this->mAllPages[$title->getNamespace()][$title->getDBkey()] = $pageId; + } + + if ( $ids && $this->mRequestedPageFields ) { + $dbr = $this->getDB(); + $fields = array_merge( array_keys( $this->mRequestedPageFields ), array( 'page_id' ) ); + // FIXME: ideally, there should be a way to do this from LinkBatch + $res = $dbr->select( 'page', + $fields, + array( 'page_id' => $ids ), + __METHOD__ + ); + foreach ( $res as $row ) { + foreach ( $this->mRequestedPageFields as $fieldName => &$fieldValues ) { + $fieldValues[$row->page_id] = $row->$fieldName; + } + } + } + if ( $usernames ) { + // Get gender information + $genderCache = GenderCache::singleton(); + $genderCache->doQuery( $usernames, __METHOD__ ); + } + + $this->profileOut(); + } + + /** * Populate this PageSet from a list of page IDs * @param array $pageIDs Array of page IDs */ diff --git a/includes/api/ApiQueryPrefixSearch.php b/includes/api/ApiQueryPrefixSearch.php index 4abd7f0..d2d360d 100644 --- a/includes/api/ApiQueryPrefixSearch.php +++ b/includes/api/ApiQueryPrefixSearch.php @@ -47,7 +47,7 @@ $searcher = new TitlePrefixSearch; $titles = $searcher->searchWithVariants( $search, $limit, $namespaces ); if ( $resultPageSet ) { - $resultPageSet->populateFromTitles( $titles ); + $resultPageSet->populateFromKnownTitles( $titles ); } else { $result = $this->getResult(); foreach ( $titles as $title ) { -- To view, visit https://gerrit.wikimedia.org/r/155622 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ibc6fe16f13b0fa341ee4962ccfaa3366b6646ed1 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: MaxSem <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
