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