Merge "Fix 'Tags' padding to keep it farther from the edge and document the source...
[lhc/web/wiklou.git] / includes / api / ApiQueryPrefixSearch.php
index 2fbc518..04d3f2c 100644 (file)
@@ -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,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;
                                }
                        }