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 / 12 |
|
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 / 9 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Search engine result issued from SearchData search engines. |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | * @ingroup Search |
| 8 | */ |
| 9 | |
| 10 | namespace MediaWiki\Search; |
| 11 | |
| 12 | use MediaWiki\MainConfigNames; |
| 13 | use MediaWiki\MediaWikiServices; |
| 14 | use MediaWiki\Title\Title; |
| 15 | |
| 16 | class SqlSearchResult extends RevisionSearchResult { |
| 17 | /** @var string[] */ |
| 18 | private $terms; |
| 19 | |
| 20 | /** |
| 21 | * @param Title $title |
| 22 | * @param string[] $terms list of parsed terms |
| 23 | */ |
| 24 | public function __construct( Title $title, array $terms ) { |
| 25 | parent::__construct( $title ); |
| 26 | $this->terms = $terms; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @return string[] |
| 31 | */ |
| 32 | public function getTermMatches(): array { |
| 33 | return $this->terms; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @param array $terms Terms to highlight (this parameter is deprecated) |
| 38 | * @return string Highlighted text snippet, null (and not '') if not supported |
| 39 | */ |
| 40 | public function getTextSnippet( $terms = [] ) { |
| 41 | $advancedSearchHighlighting = MediaWikiServices::getInstance() |
| 42 | ->getMainConfig()->get( MainConfigNames::AdvancedSearchHighlighting ); |
| 43 | $this->initText(); |
| 44 | |
| 45 | $h = new SearchHighlighter(); |
| 46 | if ( count( $this->terms ) > 0 ) { |
| 47 | if ( $advancedSearchHighlighting ) { |
| 48 | return $h->highlightText( $this->mText, $this->terms ); |
| 49 | } else { |
| 50 | return $h->highlightSimple( $this->mText, $this->terms ); |
| 51 | } |
| 52 | } else { |
| 53 | return $h->highlightNone( $this->mText ); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | } |
| 58 | |
| 59 | /** @deprecated class alias since 1.46 */ |
| 60 | class_alias( SqlSearchResult::class, 'SqlSearchResult' ); |