Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
14.29% covered (danger)
14.29%
1 / 7
CRAP
28.57% covered (danger)
28.57%
4 / 14
CirrusSearchResult
0.00% covered (danger)
0.00%
0 / 1
14.29% covered (danger)
14.29%
1 / 7
64.48
28.57% covered (danger)
28.57%
4 / 14
 __construct
0.00% covered (danger)
0.00%
0 / 1
2.26
60.00% covered (warning)
60.00%
3 / 5
 initFromTitle
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 isBrokenTitle
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 isMissingRevision
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 3
 getTitle
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getFile
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 initText
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 getDocId
n/a
0 / 0
1
n/a
0 / 0
 getScore
n/a
0 / 0
1
n/a
0 / 0
 getExplanation
n/a
0 / 0
1
n/a
0 / 0
<?php
namespace CirrusSearch\Search;
use File;
use MediaWiki\MediaWikiServices;
use SearchResult;
use SearchResultTrait;
use Title;
/**
 * Base class for SearchResult
 */
abstract class CirrusSearchResult extends SearchResult {
    use SearchResultTrait;
    /**
     * @var Title
     */
    private $title;
    /**
     * @var File
     */
    private $file;
    /**
     * @param Title $title
     */
    public function __construct( Title $title ) {
        $this->title = $title;
        if ( $this->getTitle()->getNamespace() === NS_FILE ) {
            $this->file = MediaWikiServices::getInstance()->getRepoGroup()
                ->findFile( $this->title );
        }
    }
    /**
     * Initialize from a Title and if possible initializes a corresponding
     * File.
     *
     * @param Title $title
     */
    final protected function initFromTitle( $title ) {
        // Everything is done in the constructor.
        // XXX: we do not call the SearchResultInitFromTitle hook
        // this hook is designed to fetch a particular revision
        // but the way cirrus works does not allow to vary the revision
        // text being displayed at query time.
    }
    /**
     * Check if this is result points to an invalid title
     *
     * @return bool
     */
    final public function isBrokenTitle() {
        // Title is mandatory in the constructor it would have failed earlier if the Title was broken
        return false;
    }
    /**
     * Check if target page is missing, happens when index is out of date
     *
     * @return bool
     */
    final public function isMissingRevision() {
        global $wgCirrusSearchDevelOptions;
        if ( isset( $wgCirrusSearchDevelOptions['ignore_missing_rev'] ) ) {
            return false;
        }
        return !$this->getTitle()->isKnown();
    }
    /**
     * @return Title
     */
    final public function getTitle() {
        return $this->title;
    }
    /**
     * Get the file for this page, if one exists
     * @return File|null
     */
    final public function getFile() {
        return $this->file;
    }
    /**
     * Lazy initialization of article text from DB
     * @return never
     */
    final protected function initText() {
        throw new \Exception( "initText() should not be called on CirrusSearchResult, " .
            "content must be fetched directly from the backend at query time." );
    }
    /**
     * @return string
     */
    abstract public function getDocId();
    /**
     * @return float
     */
    abstract public function getScore();
    /**
     * @return array|null
     */
    abstract public function getExplanation();
}