X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQuerySearch.php;h=51f799a25157a27582ebb9989824283711fe7867;hb=13142cd2f4684ffa6c51e5b9d14692988a408d0b;hp=7d07f5786c62fd8cc1edc4f6e4d63188d0083f8f;hpb=ad225f501c095a154bf015978e0c3263f0f1fa3f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQuerySearch.php b/includes/api/ApiQuerySearch.php index 7d07f5786c..51f799a251 100644 --- a/includes/api/ApiQuerySearch.php +++ b/includes/api/ApiQuerySearch.php @@ -116,19 +116,21 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { $this->dieUsage( $matches->getWikiText(), 'search-error' ); } - $apiResult = $this->getResult(); - // Add search meta data to result - if ( isset( $searchInfo['totalhits'] ) ) { - $totalhits = $matches->getTotalHits(); - if ( $totalhits !== null ) { + if ( $resultPageSet === null ) { + $apiResult = $this->getResult(); + // Add search meta data to result + if ( isset( $searchInfo['totalhits'] ) ) { + $totalhits = $matches->getTotalHits(); + if ( $totalhits !== null ) { + $apiResult->addValue( array( 'query', 'searchinfo' ), + 'totalhits', $totalhits ); + } + } + if ( isset( $searchInfo['suggestion'] ) && $matches->hasSuggestion() ) { $apiResult->addValue( array( 'query', 'searchinfo' ), - 'totalhits', $totalhits ); + 'suggestion', $matches->getSuggestionQuery() ); } } - if ( isset( $searchInfo['suggestion'] ) && $matches->hasSuggestion() ) { - $apiResult->addValue( array( 'query', 'searchinfo' ), - 'suggestion', $matches->getSuggestionQuery() ); - } // Add the search results to the result $terms = $wgContLang->convertForSearchResult( $matches->termMatches() ); @@ -151,7 +153,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { } $title = $result->getTitle(); - if ( is_null( $resultPageSet ) ) { + if ( $resultPageSet === null ) { $vals = array(); ApiQueryBase::addTitleInfo( $vals, $title ); @@ -202,46 +204,54 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { } $hasInterwikiResults = false; + $totalhits = null; if ( $interwiki && $resultPageSet === null && $matches->hasInterwikiResults() ) { - $matches = $matches->getInterwikiResults(); - $hasInterwikiResults = true; + foreach ( $matches->getInterwikiResults() as $matches ) { + $matches = $matches->getInterwikiResults(); + $hasInterwikiResults = true; - // Include number of results if requested - if ( isset( $searchInfo['totalhits'] ) ) { - $totalhits = $matches->getTotalHits(); - if ( $totalhits !== null ) { - $apiResult->addValue( array( 'query', 'interwikisearchinfo' ), - 'totalhits', $totalhits ); + // Include number of results if requested + if ( $resultPageSet === null && isset( $searchInfo['totalhits'] ) ) { + $totalhits += $matches->getTotalHits(); } - } - $result = $matches->next(); - while ( $result ) { - $title = $result->getTitle(); - $vals = array( - 'namespace' => $result->getInterwikiNamespaceText(), - 'title' => $title->getText(), - 'url' => $title->getFullUrl(), - ); - - // Add item to results and see whether it fits - $fit = $apiResult->addValue( - array( 'query', 'interwiki' . $this->getModuleName(), $result->getInterwikiPrefix() ), - null, - $vals - ); + $result = $matches->next(); + while ( $result ) { + $title = $result->getTitle(); + + if ( $resultPageSet === null ) { + $vals = array( + 'namespace' => $result->getInterwikiNamespaceText(), + 'title' => $title->getText(), + 'url' => $title->getFullUrl(), + ); + + // Add item to results and see whether it fits + $fit = $apiResult->addValue( + array( 'query', 'interwiki' . $this->getModuleName(), $result->getInterwikiPrefix() ), + null, + $vals + ); + + if ( !$fit ) { + // We hit the limit. We can't really provide any meaningful + // pagination info so just bail out + break; + } + } else { + $titles[] = $title; + } - if ( !$fit ) { - // We hit the limit. We can't really provide any meaningful - // pagination info so just bail out - break; + $result = $matches->next(); } - - $result = $matches->next(); + } + if ( $totalhits !== null ) { + $apiResult->addValue( array( 'query', 'interwikisearchinfo' ), + 'totalhits', $totalhits ); } } - if ( is_null( $resultPageSet ) ) { + if ( $resultPageSet === null ) { $apiResult->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'p' ); @@ -252,6 +262,10 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { } } else { $resultPageSet->populateFromTitles( $titles ); + $offset = $params['offset'] + 1; + foreach ( $titles as $index => $title ) { + $resultPageSet->setGeneratorData( $title, array( 'index' => $index + $offset ) ); + } } } @@ -318,7 +332,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { ); $alternatives = SearchEngine::getSearchTypes(); - if ( count( $alternatives ) > 1 ) { + if ( count( $alternatives ) > 0 ) { if ( $alternatives[0] === null ) { $alternatives[0] = self::BACKEND_NULL_PARAM; } @@ -331,7 +345,7 @@ class ApiQuerySearch extends ApiQueryGeneratorBase { return $params; } - public function getExamplesMessages() { + protected function getExamplesMessages() { return array( 'action=query&list=search&srsearch=meaning' => 'apihelp-query+search-example-simple',