Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
28 / 28
100.00% covered (success)
100.00%
23 / 23
CRAP
100.00% covered (success)
100.00%
1 / 1
ArrayCirrusSearchResult
100.00% covered (success)
100.00%
28 / 28
100.00% covered (success)
100.00%
23 / 23
25
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getDocId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getScore
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getExplanation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTextSnippet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTextSnippetField
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTitleSnippet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTitleSnippetField
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRedirectSnippet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRedirectSnippetField
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRedirectTitle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSectionSnippet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSectionSnippetField
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSectionTitle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCategorySnippet
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCategorySnippetField
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTimestamp
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 getWordCount
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getByteSize
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getInterwikiPrefix
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getInterwikiNamespaceText
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isFileMatch
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getExtensionData
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace CirrusSearch\Search;
4
5use MediaWiki\Title\Title;
6
7class ArrayCirrusSearchResult extends CirrusSearchResult {
8    public const DOC_ID = 'doc_id';
9    public const SCORE = 'score';
10    public const EXPLANATION = 'explanation';
11    public const TEXT_SNIPPET = 'text_snippet';
12    public const TEXT_SNIPPET_FIELD = 'text_snippet_field';
13    public const TITLE_SNIPPET = 'title_snippet';
14    public const TITLE_SNIPPET_FIELD = 'title_snippet_field';
15    public const REDIRECT_SNIPPET = 'redirect_snippet';
16    public const REDIRECT_SNIPPET_FIELD = 'redirect_snippet_field';
17    public const REDIRECT_TITLE = 'redirect_title';
18    public const SECTION_SNIPPET = 'section_snippet';
19    public const SECTION_SNIPPET_FIELD = 'section_snippet_field';
20    public const SECTION_TITLE = 'section_title';
21    public const CATEGORY_SNIPPET = 'category_snippet';
22    public const CATEGORY_SNIPPET_FIELD = 'category_snippet_field';
23    public const TIMESTAMP = 'timestamp';
24    public const WORD_COUNT = 'word_count';
25    public const BYTE_SIZE = 'byte_size';
26    public const INTERWIKI_NAMESPACE_TEXT = 'interwiki_namespace_text';
27    public const IS_FILE_MATCH = 'is_file_match';
28    public const EXTRA_FIELDS = 'extra_fields';
29
30    /**
31     * @var array
32     */
33    private $data;
34
35    public function __construct( Title $title, array $data ) {
36        parent::__construct( $title );
37        $this->data = $data;
38    }
39
40    /**
41     * @return string
42     */
43    public function getDocId() {
44        return $this->data[self::DOC_ID];
45    }
46
47    /**
48     * @return float
49     */
50    public function getScore() {
51        return $this->data[self::SCORE] ?? 0.0;
52    }
53
54    /**
55     * @return array|null
56     */
57    public function getExplanation() {
58        return $this->data[self::EXPLANATION] ?? null;
59    }
60
61    /**
62     * @inheritDoc
63     */
64    public function getTextSnippet( $terms = [] ) {
65        return $this->data[self::TEXT_SNIPPET] ?? '';
66    }
67
68    /**
69     * @inheritDoc
70     */
71    public function getTextSnippetField() {
72        return $this->data[self::TEXT_SNIPPET_FIELD] ?? '';
73    }
74
75    /**
76     * @inheritDoc
77     */
78    public function getTitleSnippet() {
79        return $this->data[self::TITLE_SNIPPET] ?? '';
80    }
81
82    /**
83     * @inheritDoc
84     */
85    public function getTitleSnippetField() {
86        return $this->data[self::TITLE_SNIPPET_FIELD] ?? '';
87    }
88
89    /**
90     * @inheritDoc
91     */
92    public function getRedirectSnippet() {
93        return $this->data[self::REDIRECT_SNIPPET] ?? '';
94    }
95
96    /**
97     * @inheritDoc
98     */
99    public function getRedirectSnippetField() {
100        return $this->data[self::REDIRECT_SNIPPET_FIELD] ?? '';
101    }
102
103    /**
104     * @inheritDoc
105     */
106    public function getRedirectTitle() {
107        return $this->data[self::REDIRECT_TITLE] ?? null;
108    }
109
110    /**
111     * @inheritDoc
112     */
113    public function getSectionSnippet() {
114        return $this->data[self::SECTION_SNIPPET] ?? '';
115    }
116
117    /**
118     * @inheritDoc
119     */
120    public function getSectionSnippetField() {
121        return $this->data[self::SECTION_SNIPPET_FIELD] ?? '';
122    }
123
124    /**
125     * @inheritDoc
126     */
127    public function getSectionTitle() {
128        return $this->data[self::SECTION_TITLE] ?? null;
129    }
130
131    /**
132     * @inheritDoc
133     */
134    public function getCategorySnippet() {
135        return $this->data[self::CATEGORY_SNIPPET] ?? '';
136    }
137
138    /**
139     * @inheritDoc
140     */
141    public function getCategorySnippetField() {
142        return $this->data[self::CATEGORY_SNIPPET_FIELD] ?? '';
143    }
144
145    /**
146     * @inheritDoc
147     */
148    public function getTimestamp() {
149        $ts = $this->data[self::TIMESTAMP] ?? null;
150        return $ts !== null ? $ts->getTimestamp( TS_MW ) : '';
151    }
152
153    /**
154     * @inheritDoc
155     */
156    public function getWordCount() {
157        return $this->data[self::WORD_COUNT] ?? 0;
158    }
159
160    /**
161     * @inheritDoc
162     */
163    public function getByteSize() {
164        return $this->data[self::BYTE_SIZE] ?? 0;
165    }
166
167    /**
168     * @inheritDoc
169     */
170    public function getInterwikiPrefix() {
171        return $this->getTitle()->getInterwiki();
172    }
173
174    /**
175     * @inheritDoc
176     */
177    public function getInterwikiNamespaceText() {
178        return $this->data[self::INTERWIKI_NAMESPACE_TEXT] ?? '';
179    }
180
181    /**
182     * @inheritDoc
183     */
184    public function isFileMatch() {
185        return $this->data[self::IS_FILE_MATCH] ?? false;
186    }
187
188    /**
189     * @return array[]
190     */
191    public function getExtensionData() {
192        $extensionData = parent::getExtensionData();
193        if ( isset( $this->data[self::EXTRA_FIELDS] ) ) {
194            $extensionData[self::EXTRA_FIELDS] = $this->data[self::EXTRA_FIELDS];
195        }
196        return $extensionData;
197    }
198}