Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
23 / 23 |
|
100.00% |
18 / 18 |
CRAP | |
100.00% |
1 / 1 |
ArrayCirrusSearchResult | |
100.00% |
23 / 23 |
|
100.00% |
18 / 18 |
20 | |
100.00% |
1 / 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 | |||
getTitleSnippet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getRedirectSnippet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getRedirectTitle | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getSectionSnippet | |
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 | |||
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 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 TITLE_SNIPPET = 'title_snippet'; |
13 | public const REDIRECT_SNIPPET = 'redirect_snippet'; |
14 | public const REDIRECT_TITLE = 'redirect_title'; |
15 | public const SECTION_SNIPPET = 'section_snippet'; |
16 | public const SECTION_TITLE = 'section_title'; |
17 | public const CATEGORY_SNIPPET = 'category_snippet'; |
18 | public const TIMESTAMP = 'timestamp'; |
19 | public const WORD_COUNT = 'word_count'; |
20 | public const BYTE_SIZE = 'byte_size'; |
21 | public const INTERWIKI_NAMESPACE_TEXT = 'interwiki_namespace_text'; |
22 | public const IS_FILE_MATCH = 'is_file_match'; |
23 | public const EXTRA_FIELDS = 'extra_fields'; |
24 | |
25 | /** |
26 | * @var array |
27 | */ |
28 | private $data; |
29 | |
30 | public function __construct( Title $title, array $data ) { |
31 | parent::__construct( $title ); |
32 | $this->data = $data; |
33 | } |
34 | |
35 | /** |
36 | * @return string |
37 | */ |
38 | public function getDocId() { |
39 | return $this->data[self::DOC_ID]; |
40 | } |
41 | |
42 | /** |
43 | * @return float |
44 | */ |
45 | public function getScore() { |
46 | return $this->data[self::SCORE] ?? 0.0; |
47 | } |
48 | |
49 | /** |
50 | * @return array|null |
51 | */ |
52 | public function getExplanation() { |
53 | return $this->data[self::EXPLANATION] ?? null; |
54 | } |
55 | |
56 | /** |
57 | * @inheritDoc |
58 | */ |
59 | public function getTextSnippet( $terms = [] ) { |
60 | return $this->data[self::TEXT_SNIPPET] ?? ''; |
61 | } |
62 | |
63 | /** |
64 | * @inheritDoc |
65 | */ |
66 | public function getTitleSnippet() { |
67 | return $this->data[self::TITLE_SNIPPET] ?? ''; |
68 | } |
69 | |
70 | /** |
71 | * @inheritDoc |
72 | */ |
73 | public function getRedirectSnippet() { |
74 | return $this->data[self::REDIRECT_SNIPPET] ?? ''; |
75 | } |
76 | |
77 | /** |
78 | * @inheritDoc |
79 | */ |
80 | public function getRedirectTitle() { |
81 | return $this->data[self::REDIRECT_TITLE] ?? null; |
82 | } |
83 | |
84 | /** |
85 | * @inheritDoc |
86 | */ |
87 | public function getSectionSnippet() { |
88 | return $this->data[self::SECTION_SNIPPET] ?? ''; |
89 | } |
90 | |
91 | /** |
92 | * @inheritDoc |
93 | */ |
94 | public function getSectionTitle() { |
95 | return $this->data[self::SECTION_TITLE] ?? null; |
96 | } |
97 | |
98 | /** |
99 | * @inheritDoc |
100 | */ |
101 | public function getCategorySnippet() { |
102 | return $this->data[self::CATEGORY_SNIPPET] ?? ''; |
103 | } |
104 | |
105 | /** |
106 | * @inheritDoc |
107 | */ |
108 | public function getTimestamp() { |
109 | $ts = $this->data[self::TIMESTAMP] ?? null; |
110 | return $ts !== null ? $ts->getTimestamp( TS_MW ) : ''; |
111 | } |
112 | |
113 | /** |
114 | * @inheritDoc |
115 | */ |
116 | public function getWordCount() { |
117 | return $this->data[self::WORD_COUNT] ?? 0; |
118 | } |
119 | |
120 | /** |
121 | * @inheritDoc |
122 | */ |
123 | public function getByteSize() { |
124 | return $this->data[self::BYTE_SIZE] ?? 0; |
125 | } |
126 | |
127 | /** |
128 | * @inheritDoc |
129 | */ |
130 | public function getInterwikiPrefix() { |
131 | return $this->getTitle()->getInterwiki(); |
132 | } |
133 | |
134 | /** |
135 | * @inheritDoc |
136 | */ |
137 | public function getInterwikiNamespaceText() { |
138 | return $this->data[self::INTERWIKI_NAMESPACE_TEXT] ?? ''; |
139 | } |
140 | |
141 | /** |
142 | * @inheritDoc |
143 | */ |
144 | public function isFileMatch() { |
145 | return $this->data[self::IS_FILE_MATCH] ?? false; |
146 | } |
147 | |
148 | /** |
149 | * @return array[] |
150 | */ |
151 | public function getExtensionData() { |
152 | $extensionData = parent::getExtensionData(); |
153 | if ( isset( $this->data[self::EXTRA_FIELDS] ) ) { |
154 | $extensionData[self::EXTRA_FIELDS] = $this->data[self::EXTRA_FIELDS]; |
155 | } |
156 | return $extensionData; |
157 | } |
158 | } |