Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
80.00% |
28 / 35 |
|
95.83% |
23 / 24 |
CRAP | |
0.00% |
0 / 1 |
ArrayCirrusSearchResult | |
80.00% |
28 / 35 |
|
95.83% |
23 / 24 |
35.73 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getDocId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getScore | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getExplanation | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getTextSnippet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getTextSnippetField | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getTitleSnippet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getTitleSnippetField | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getRedirectSnippet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getRedirectSnippetField | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
clearRedirectTitle | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
getRedirectTitle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getSectionSnippet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getSectionSnippetField | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getSectionTitle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getCategorySnippet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getCategorySnippetField | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getTimestamp | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
getWordCount | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getByteSize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getInterwikiPrefix | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getInterwikiNamespaceText | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isFileMatch | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getExtensionData | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Search; |
4 | |
5 | use MediaWiki\Title\Title; |
6 | |
7 | class 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 | protected function clearRedirectTitle(): bool { |
107 | unset( |
108 | $this->data[self::REDIRECT_SNIPPET], |
109 | $this->data[self::REDIRECT_SNIPPET_FIELD] ); |
110 | |
111 | return !$this->containsHighlight( $this->getTextSnippet() ) |
112 | && $this->getTitleSnippet() === '' |
113 | && $this->getSectionSnippet() === '' |
114 | && $this->getCategorySnippet() === ''; |
115 | } |
116 | |
117 | /** |
118 | * @inheritDoc |
119 | */ |
120 | public function getRedirectTitle() { |
121 | return $this->data[self::REDIRECT_TITLE] ?? null; |
122 | } |
123 | |
124 | /** |
125 | * @inheritDoc |
126 | */ |
127 | public function getSectionSnippet() { |
128 | return $this->data[self::SECTION_SNIPPET] ?? ''; |
129 | } |
130 | |
131 | /** |
132 | * @inheritDoc |
133 | */ |
134 | public function getSectionSnippetField() { |
135 | return $this->data[self::SECTION_SNIPPET_FIELD] ?? ''; |
136 | } |
137 | |
138 | /** |
139 | * @inheritDoc |
140 | */ |
141 | public function getSectionTitle() { |
142 | return $this->data[self::SECTION_TITLE] ?? null; |
143 | } |
144 | |
145 | /** |
146 | * @inheritDoc |
147 | */ |
148 | public function getCategorySnippet() { |
149 | return $this->data[self::CATEGORY_SNIPPET] ?? ''; |
150 | } |
151 | |
152 | /** |
153 | * @inheritDoc |
154 | */ |
155 | public function getCategorySnippetField() { |
156 | return $this->data[self::CATEGORY_SNIPPET_FIELD] ?? ''; |
157 | } |
158 | |
159 | /** |
160 | * @inheritDoc |
161 | */ |
162 | public function getTimestamp() { |
163 | $ts = $this->data[self::TIMESTAMP] ?? null; |
164 | return $ts !== null ? $ts->getTimestamp( TS_MW ) : ''; |
165 | } |
166 | |
167 | /** |
168 | * @inheritDoc |
169 | */ |
170 | public function getWordCount() { |
171 | return $this->data[self::WORD_COUNT] ?? 0; |
172 | } |
173 | |
174 | /** |
175 | * @inheritDoc |
176 | */ |
177 | public function getByteSize() { |
178 | return $this->data[self::BYTE_SIZE] ?? 0; |
179 | } |
180 | |
181 | /** |
182 | * @inheritDoc |
183 | */ |
184 | public function getInterwikiPrefix() { |
185 | return $this->getTitle()->getInterwiki(); |
186 | } |
187 | |
188 | /** |
189 | * @inheritDoc |
190 | */ |
191 | public function getInterwikiNamespaceText() { |
192 | return $this->data[self::INTERWIKI_NAMESPACE_TEXT] ?? ''; |
193 | } |
194 | |
195 | /** |
196 | * @inheritDoc |
197 | */ |
198 | public function isFileMatch() { |
199 | return $this->data[self::IS_FILE_MATCH] ?? false; |
200 | } |
201 | |
202 | /** |
203 | * @return array[] |
204 | */ |
205 | public function getExtensionData() { |
206 | $extensionData = parent::getExtensionData(); |
207 | if ( isset( $this->data[self::EXTRA_FIELDS] ) ) { |
208 | $extensionData[self::EXTRA_FIELDS] = $this->data[self::EXTRA_FIELDS]; |
209 | } |
210 | return $extensionData; |
211 | } |
212 | } |