X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryPrefixSearch.php;h=04d3f2c9fcac60fa888331b325713129a21fe652;hb=f96aaf6833d052d10d46af47540fff995362433e;hp=5606f3c922edf681089f268095d786ae2ea452ea;hpb=dae4c94d893057345f62a3d498fb85c0a54de5a6;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryPrefixSearch.php b/includes/api/ApiQueryPrefixSearch.php index 5606f3c922..04d3f2c9fc 100644 --- a/includes/api/ApiQueryPrefixSearch.php +++ b/includes/api/ApiQueryPrefixSearch.php @@ -51,19 +51,20 @@ 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 ) { + $resultPageSet->setRedirectMergePolicy( function ( array $current, array $new ) { if ( !isset( $current['index'] ) || $new['index'] < $current['index'] ) { $current['index'] = $new['index']; } 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,10 +73,6 @@ 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() ), 'title' => $title->getPrefixedText(), @@ -86,8 +83,9 @@ class ApiQueryPrefixSearch extends ApiQueryGeneratorBase { $vals['pageid'] = intval( $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; } }