3 use MediaWiki\MediaWikiServices
;
5 class MockSearchEngine
extends SearchEngine
{
6 /** @var SearchResult[][] */
7 private static $results = [];
8 /** @var SearchResultSet[][] */
9 private static $interwikiResults = [];
11 public static function clearMockResults() {
13 self
::$interwikiResults = [];
17 * @param string $query The query searched for *after* initial
18 * transformations have been applied.
19 * @param SearchResult[] $results The results to return for $query
21 public static function addMockResults( $query, array $results ) {
22 self
::$results[$query] = $results;
23 $lc = MediaWikiServices
::getInstance()->getLinkCache();
24 foreach ( $results as $result ) {
25 // TODO: better page ids? Does it matter?
26 $lc->addGoodLinkObj( mt_rand(), $result->getTitle() );
31 * @param SearchResultSet[][] $interwikiResults
33 public static function setMockInterwikiResults( array $interwikiResults ) {
34 self
::$interwikiResults = $interwikiResults;
37 protected function doSearchText( $term ) {
38 if ( isset( self
::$results[ $term ] ) ) {
39 $results = array_slice( self
::$results[ $term ], $this->offset
, $this->limit
);
43 return new MockSearchResultSet( $results, self
::$interwikiResults );