X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryPrefixSearch.php;h=e5f611fa3a3d780a1ac38bcbe38208ebb4ac865f;hb=701b642fdc55de095e050cc56d65c61225473a06;hp=2fbc518b1e24bfb021257b3215477935a7466ee0;hpb=237d3271fd313ebe09858a5c442a91216a7b61cf;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryPrefixSearch.php b/includes/api/ApiQueryPrefixSearch.php index 2fbc518b1e..e5f611fa3a 100644 --- a/includes/api/ApiQueryPrefixSearch.php +++ b/includes/api/ApiQueryPrefixSearch.php @@ -51,7 +51,12 @@ class ApiQueryPrefixSearch extends ApiQueryGeneratorBase { $offset = $params['offset']; $searchEngine = $this->buildSearchEngine( $params ); - $titles = $searchEngine->extractTitles( $searchEngine->completionSearchWithVariants( $search ) ); + $suggestions = $searchEngine->completionSearchWithVariants( $search ); + $titles = $searchEngine->extractTitles( $suggestions ); + + if ( $suggestions->hasMoreResults() ) { + $this->setContinueEnumParameter( 'offset', $offset + $limit ); + } if ( $resultPageSet ) { $resultPageSet->setRedirectMergePolicy( function ( array $current, array $new ) { @@ -60,10 +65,6 @@ class ApiQueryPrefixSearch extends ApiQueryGeneratorBase { } return $current; } ); - if ( count( $titles ) > $limit ) { - $this->setContinueEnumParameter( 'offset', $offset + $limit ); - array_pop( $titles ); - } $resultPageSet->populateFromTitles( $titles ); foreach ( $titles as $index => $title ) { $resultPageSet->setGeneratorData( $title, [ 'index' => $index + $offset + 1 ] ); @@ -72,22 +73,19 @@ class ApiQueryPrefixSearch extends ApiQueryGeneratorBase { $result = $this->getResult(); $count = 0; foreach ( $titles as $title ) { - if ( ++$count > $limit ) { - $this->setContinueEnumParameter( 'offset', $offset + $limit ); - break; - } $vals = [ - 'ns' => intval( $title->getNamespace() ), + 'ns' => (int)$title->getNamespace(), 'title' => $title->getPrefixedText(), ]; if ( $title->isSpecialPage() ) { $vals['special'] = true; } else { - $vals['pageid'] = intval( $title->getArticleID() ); + $vals['pageid'] = (int)$title->getArticleID(); } $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $vals ); + ++$count; if ( !$fit ) { - $this->setContinueEnumParameter( 'offset', $offset + $count - 1 ); + $this->setContinueEnumParameter( 'offset', $offset + $count ); break; } }