EBernhardson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/279083
Change subject: Backend support for test swapping second and third result
......................................................................
Backend support for test swapping second and third result
Bug: T127878
Change-Id: Ie198bc73e17db182af8402c6934a9f93845f3e7e
---
M includes/CirrusSearch.php
M includes/Search/ResultSet.php
2 files changed, 30 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch
refs/changes/83/279083/1
diff --git a/includes/CirrusSearch.php b/includes/CirrusSearch.php
index 2b969e4..7bdf754 100644
--- a/includes/CirrusSearch.php
+++ b/includes/CirrusSearch.php
@@ -140,6 +140,12 @@
$matches->isQueryRewriteAllowed(
$GLOBALS['wgCirrusSearchInterwikiThreshold'] ) ) {
$matches = $this->searchTextSecondTry( $term, $matches
);
}
+
+ if ( $this->request && $this->request->getVal( 'cirrusSRTest' )
=== 'yes' ) {
+ // note these are 0 indexed, so swap second and third
+ $matches->swapResults( 1, 2 );
+ }
+
return $matches;
}
diff --git a/includes/Search/ResultSet.php b/includes/Search/ResultSet.php
index af51d04..5634d53 100644
--- a/includes/Search/ResultSet.php
+++ b/includes/Search/ResultSet.php
@@ -32,6 +32,7 @@
private $searchContainedSyntax;
private $interwikiPrefix,$interwikiResults;
private $rewrittenQuery;
+ private $swappedResultIter;
public function __construct( $suggestPrefixes, $suggestSuffixes, $res,
$searchContainedSyntax, $interwiki = '' ) {
$this->result = $res;
@@ -189,12 +190,33 @@
}
/**
+ * @param integer $first 0-indexed result to swap with $second
+ * @param integer $second 0-indexed result to swap with $first
+ */
+ public function swapResults( $first, $second ) {
+ $iter = $this->swappedResultIter ? $this->swappedResultIter :
$this->result;
+ $results = iterator_to_array( $iter );
+ if ( count( $results ) > $first ) {
+ $firstElem = $results[$first];
+ if ( count( $results ) >= $second ) {
+ $results[$first] = $results[$second];
+ $results[$second] = $firstElem;
+ } else {
+ array_splice( $results, $first, 1 );
+ $results[] = $firstElem;
+ }
+ }
+ $this->swappedResultIter = new \ArrayIterator( $results );
+ }
+
+ /**
* @return Result|false
*/
public function next() {
- $current = $this->result->current();
+ $iter = $this->swappedResultIter ? $this->swappedResultIter :
$this->result;
+ $current = $iter->current();
if ( $current ) {
- $this->result->next();
+ $iter->next();
return new Result( $this->result, $current,
$this->interwikiPrefix );
}
return false;
--
To view, visit https://gerrit.wikimedia.org/r/279083
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie198bc73e17db182af8402c6934a9f93845f3e7e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits