44 public function rescore( $search, $namespaces, $srchres, $limit ) {
46 $ns = in_array(
NS_MAIN, $namespaces ) ?
NS_MAIN : reset( $namespaces );
48 if ( !
$t || !
$t->exists() ) {
52 $string =
$t->getPrefixedText();
53 $key = array_search( $string, $srchres );
54 if ( $key !==
false ) {
56 return $this->
pullFront( $key, $srchres );
59 if (
$t->isRedirect() ) {
61 $key = array_search( $target, $srchres );
62 if ( $key !==
false ) {
70 return $this->
pullFront( $key, $srchres );
73 if ( isset( $redirectTargetsToRedirect[$target] ) ) {
78 return $this->
pullFront( $redirectTargetsToRedirect[$target], $srchres );
82 if ( isset( $redirectTargetsToRedirect[$string] ) ) {
85 array_splice( $srchres, $redirectTargetsToRedirect[$string], 1 );
86 array_unshift( $srchres, $string );
92 array_unshift( $srchres, $string );
94 if ( count( $srchres ) > $limit ) {
95 array_pop( $srchres );
107 foreach ( $titles as $key => $titleText ) {
116 $result[$target] = $key;
129 $cut = array_splice( $array, $key, 1 );
130 array_unshift( $array, $cut[0] );
140 $redirectStore = MediaWikiServices::getInstance()->getRedirectStore();
141 $redir = $redirectStore->getRedirectTarget(
$title );
145 return $redir ? $redir->getPrefixedText() :
null;
An utility class to rescore search results by looking for an exact match in the db and add the page f...
getRedirectTarget( $title)
Get a redirect's destination from a title.
rescore( $search, $namespaces, $srchres, $limit)
Default search backend does proper prefix searching, but custom backends may sort based on other algo...
redirectTargetsToRedirect(array $titles)
pullFront( $key, array $array)
Returns an array where the element of $array at index $key becomes the first element.
static castFromLinkTarget( $linkTarget)
Same as newFromLinkTarget, but if passed null, returns null.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.