Merge "Support custom offsets from SearchResultSet"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 19 Jul 2017 10:57:28 +0000 (10:57 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 19 Jul 2017 10:57:28 +0000 (10:57 +0000)
includes/search/SearchResultSet.php
includes/specials/SpecialSearch.php

index 978db27..89d2299 100644 (file)
@@ -264,4 +264,14 @@ class SearchResultSet {
                $result->setExtensionData( $this->extraData[$id] );
                return $this->extraData[$id];
        }
+
+       /**
+        * @return int|null The offset the current page starts at. Typically
+        *  this should be null to allow the UI to decide on its own, but in
+        *  special cases like interleaved AB tests specifying explicitly is
+        *  necessary.
+        */
+       public function getOffset() {
+               return null;
+       }
 }
index e5adeb5..eeb8823 100644 (file)
@@ -435,9 +435,17 @@ class SpecialSearch extends SpecialPage {
 
                // prev/next links
                if ( $totalRes > $this->limit || $this->offset ) {
+                       // Allow matches to define the correct offset, as interleaved
+                       // AB testing may require a different next page offset.
+                       if ( $textMatches && $textMatches->getOffset() !== null ) {
+                               $offset = $textMatches->getOffset();
+                       } else {
+                               $offset = $this->offset;
+                       }
+
                        $prevnext = $this->getLanguage()->viewPrevNext(
                                $this->getPageTitle(),
-                               $this->offset,
+                               $offset,
                                $this->limit,
                                $this->powerSearchOptions() + [ 'search' => $term ],
                                $this->limit + $this->offset >= $totalRes