Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
14.29% covered (danger)
14.29%
2 / 14
28.57% covered (danger)
28.57%
2 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
CirrusSearchResult
14.29% covered (danger)
14.29%
2 / 14
28.57% covered (danger)
28.57%
2 / 7
72.97
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 initFromTitle
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isBrokenTitle
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isMissingRevision
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getTitle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFile
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 initText
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getDocId
n/a
0 / 0
n/a
0 / 0
0
 getScore
n/a
0 / 0
n/a
0 / 0
0
 getExplanation
n/a
0 / 0
n/a
0 / 0
0
1<?php
2
3namespace CirrusSearch\Search;
4
5use File;
6use LogicException;
7use MediaWiki\MediaWikiServices;
8use MediaWiki\Title\Title;
9use SearchResult;
10use SearchResultTrait;
11
12/**
13 * Base class for SearchResult
14 */
15abstract class CirrusSearchResult extends SearchResult {
16    use SearchResultTrait;
17
18    /**
19     * @var Title
20     */
21    private $title;
22
23    /**
24     * @var ?File
25     */
26    private $file;
27
28    /**
29     * @var bool
30     */
31    private $checkedForFile = false;
32
33    /**
34     * @param Title $title
35     */
36    public function __construct( Title $title ) {
37        $this->title = $title;
38    }
39
40    /**
41     * Initialize from a Title and if possible initializes a corresponding
42     * File.
43     *
44     * @param Title $title
45     */
46    final protected function initFromTitle( $title ) {
47        // Everything is done in the constructor.
48        // XXX: we do not call the SearchResultInitFromTitle hook
49        // this hook is designed to fetch a particular revision
50        // but the way cirrus works does not allow to vary the revision
51        // text being displayed at query time.
52    }
53
54    /**
55     * Check if this is result points to an invalid title
56     *
57     * @return bool
58     */
59    final public function isBrokenTitle() {
60        // Title is mandatory in the constructor it would have failed earlier if the Title was broken
61        return false;
62    }
63
64    /**
65     * Check if target page is missing, happens when index is out of date
66     *
67     * @return bool
68     */
69    final public function isMissingRevision() {
70        global $wgCirrusSearchDevelOptions;
71        if ( isset( $wgCirrusSearchDevelOptions['ignore_missing_rev'] ) ) {
72            return false;
73        }
74        return !$this->getTitle()->isKnown();
75    }
76
77    /**
78     * @return Title
79     */
80    final public function getTitle() {
81        return $this->title;
82    }
83
84    /**
85     * Get the file for this page, if one exists
86     * @return File|null
87     */
88    final public function getFile() {
89        if ( !$this->checkedForFile && $this->getTitle()->getNamespace() === NS_FILE ) {
90            $this->checkedForFile = true;
91            $this->file = MediaWikiServices::getInstance()->getRepoGroup()
92                ->findFile( $this->title );
93        }
94        return $this->file;
95    }
96
97    /**
98     * Lazy initialization of article text from DB
99     * @return never
100     */
101    final protected function initText() {
102        throw new LogicException( "initText() should not be called on CirrusSearchResult, " .
103            "content must be fetched directly from the backend at query time." );
104    }
105
106    /**
107     * @return string
108     */
109    abstract public function getDocId();
110
111    /**
112     * @return float
113     */
114    abstract public function getScore();
115
116    /**
117     * @return array|null
118     */
119    abstract public function getExplanation();
120}