Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4096054
MockSearchEngine.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
MockSearchEngine.php
View Options
<?php
class
MockSearchEngine
extends
SearchEngine
{
use
LinkCacheTestTrait
;
/** @var SearchResult[][] */
private
static
$results
=
[];
/** @var ISearchResultSet[][] */
private
static
$interwikiResults
=
[];
public
static
function
clearMockResults
()
{
self
::
$results
=
[];
self
::
$interwikiResults
=
[];
}
/**
* @param string $query The query searched for *after* initial
* transformations have been applied.
* @param SearchResult[] $results The results to return for $query
*/
public
static
function
addMockResults
(
$query
,
array
$results
)
{
$mockSearchEngine
=
new
self
();
foreach
(
$results
as
&
$result
)
{
// Resolve deferred results; needed to work around T203279
if
(
is_callable
(
$result
)
)
{
$result
=
$result
();
}
// TODO: better page ids? Does it matter?
$mockSearchEngine
->
addGoodLinkObject
(
mt_rand
(),
$result
->
getTitle
()
);
}
self
::
$results
[
$query
]
=
$results
;
}
/**
* @param ISearchResultSet[][] $interwikiResults
*/
public
static
function
setMockInterwikiResults
(
array
$interwikiResults
)
{
self
::
$interwikiResults
=
$interwikiResults
;
}
protected
function
doSearchText
(
$term
)
{
if
(
isset
(
self
::
$results
[
$term
]
)
)
{
$results
=
array_slice
(
self
::
$results
[
$term
],
$this
->
offset
,
$this
->
limit
);
}
else
{
$results
=
[];
}
return
new
MockSearchResultSet
(
$results
,
self
::
$interwikiResults
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Aug 18, 14:11 (4 w, 3 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
a2/11/bacb862458bae74380150e8987e0
Default Alt Text
MockSearchEngine.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment