EBernhardson has uploaded a new change for review. https://gerrit.wikimedia.org/r/320551
Change subject: Accept 'OK' status results from search engine ...................................................................... Accept 'OK' status results from search engine Historically code that talks to the SearchEngine has been treating anything other than a 'Good' result, such as results but with a warning (perhaps the query timed out and only gave partial results) as a complete failure. Adjust the handling to report results from an 'OK' status response while attaching any warnings to the api response, or in a notiable red box on Special:Search. Bug: T134157 Change-Id: Ic5e0db727790f4fd189caa54ea5f01672d6a8ea4 --- M includes/api/ApiQuerySearch.php M includes/specials/SpecialSearch.php 2 files changed, 31 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/51/320551/1 diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php index 6be5198..488d7db 100644 --- a/includes/api/ApiQuerySearch.php +++ b/includes/api/ApiQuerySearch.php @@ -107,10 +107,25 @@ $matches = $search->searchText( $query ); } } - if ( is_null( $matches ) ) { + + if ( $matches instanceof Status ) { + $status = $matches; + $matches = $status->getValue(); + } else { + $status = null; + } + + if ( $status ) { + if ( $status->isOK() ) { + $this->getMain()->getErrorFormatter()->addMessagesFromStatus( + $this->getModuleName(), + $status + ); + } else { + $this->dieUsage( $matches->getWikiText( false, false, 'en' ), 'search-error' ); + } + } elseif ( is_null( $matches ) ) { $this->dieUsage( "{$what} search is disabled", "search-{$what}-disabled" ); - } elseif ( $matches instanceof Status && !$matches->isGood() ) { - $this->dieUsage( $matches->getWikiText( false, false, 'en' ), 'search-error' ); } if ( $resultPageSet === null ) { diff --git a/includes/specials/SpecialSearch.php b/includes/specials/SpecialSearch.php index 9280b04..add2abb 100644 --- a/includes/specials/SpecialSearch.php +++ b/includes/specials/SpecialSearch.php @@ -295,12 +295,12 @@ $textStatus = null; if ( $textMatches instanceof Status ) { $textStatus = $textMatches; - $textMatches = null; + $textMatches = $textStatus->getValue(); } // did you mean... suggestions $didYouMeanHtml = ''; - if ( $showSuggestion && $textMatches && !$textStatus ) { + if ( $showSuggestion && $textMatches ) { if ( $textMatches->hasRewrittenQuery() ) { $didYouMeanHtml = $this->getDidYouMeanRewrittenHtml( $term, $textMatches ); } elseif ( $textMatches->hasSuggestion() ) { @@ -360,6 +360,14 @@ $out->addHTML( "<div class='searchresults'>" ); + if ( $textStatus && $textStatus->getErrors() ) { + $out->addHTML( Html::rawElement( + 'div', + [ 'class' => 'errorbox' ], + $textStatus->getHTML( 'search-error' ) + ) ); + } + // prev/next links $prevnext = null; if ( $num || $this->offset ) { @@ -388,7 +396,8 @@ } $titleMatches->free(); } - if ( $textMatches && !$textStatus ) { + + if ( $textMatches ) { // output appropriate heading if ( $numTextMatches > 0 && $numTitleMatches > 0 ) { $out->addHTML( '<div class="mw-search-visualclear"></div>' ); @@ -413,7 +422,7 @@ $textMatches->hasInterwikiResults( SearchResultSet::INLINE_RESULTS ); if ( $num === 0 ) { - if ( $textStatus ) { + if ( !$textStatus->isOK() ) { $out->addHTML( '<div class="error">' . $textStatus->getMessage( 'search-error' ) . '</div>' ); } else { -- To view, visit https://gerrit.wikimedia.org/r/320551 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic5e0db727790f4fd189caa54ea5f01672d6a8ea4 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits