Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
SqlSearchResult | |
0.00% |
0 / 13 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getTermMatches | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTextSnippet | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | /** |
3 | * Search engine result issued from SearchData search engines. |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program; if not, write to the Free Software Foundation, Inc., |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | * http://www.gnu.org/copyleft/gpl.html |
19 | * |
20 | * @file |
21 | * @ingroup Search |
22 | */ |
23 | |
24 | use MediaWiki\MainConfigNames; |
25 | use MediaWiki\MediaWikiServices; |
26 | use MediaWiki\Title\Title; |
27 | |
28 | class SqlSearchResult extends RevisionSearchResult { |
29 | /** @var string[] */ |
30 | private $terms; |
31 | |
32 | /** |
33 | * @param Title $title |
34 | * @param string[] $terms list of parsed terms |
35 | */ |
36 | public function __construct( Title $title, array $terms ) { |
37 | parent::__construct( $title ); |
38 | $this->terms = $terms; |
39 | } |
40 | |
41 | /** |
42 | * @return string[] |
43 | */ |
44 | public function getTermMatches(): array { |
45 | return $this->terms; |
46 | } |
47 | |
48 | /** |
49 | * @param array $terms Terms to highlight (this parameter is deprecated) |
50 | * @return string Highlighted text snippet, null (and not '') if not supported |
51 | */ |
52 | public function getTextSnippet( $terms = [] ) { |
53 | $advancedSearchHighlighting = MediaWikiServices::getInstance() |
54 | ->getMainConfig()->get( MainConfigNames::AdvancedSearchHighlighting ); |
55 | $this->initText(); |
56 | |
57 | $h = new SearchHighlighter(); |
58 | if ( count( $this->terms ) > 0 ) { |
59 | if ( $advancedSearchHighlighting ) { |
60 | return $h->highlightText( $this->mText, $this->terms ); |
61 | } else { |
62 | return $h->highlightSimple( $this->mText, $this->terms ); |
63 | } |
64 | } else { |
65 | return $h->highlightNone( $this->mText ); |
66 | } |
67 | } |
68 | |
69 | } |