Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
75.00% |
6 / 8 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| EntityElasticTermResult | |
75.00% |
6 / 8 |
|
50.00% |
1 / 2 |
3.14 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getTermSearchResult | |
71.43% |
5 / 7 |
|
0.00% |
0 / 1 |
2.09 | |||
| 1 | <?php |
| 2 | |
| 3 | declare( strict_types = 1 ); |
| 4 | |
| 5 | namespace Wikibase\Search\Elastic; |
| 6 | |
| 7 | use Wikibase\DataModel\Entity\EntityIdParser; |
| 8 | use Wikibase\DataModel\Entity\EntityIdParsingException; |
| 9 | use Wikibase\DataModel\Term\Term; |
| 10 | use Wikibase\Lib\Interactors\TermSearchResult; |
| 11 | use Wikibase\Lib\TermLanguageFallbackChain; |
| 12 | |
| 13 | /** |
| 14 | * This result type implements the result for searching |
| 15 | * a Wikibase entity by its label or alias. |
| 16 | * |
| 17 | * (This class is not directly related to EntityResult.) |
| 18 | * |
| 19 | * @license GPL-2.0-or-later |
| 20 | */ |
| 21 | class EntityElasticTermResult extends ElasticTermResult { |
| 22 | |
| 23 | public function __construct( |
| 24 | private readonly EntityIdParser $idParser, |
| 25 | array $searchLanguageCodes, |
| 26 | string $highlightSubField, |
| 27 | TermLanguageFallbackChain $displayFallbackChain, |
| 28 | ) { |
| 29 | parent::__construct( $searchLanguageCodes, $displayFallbackChain, $highlightSubField ); |
| 30 | } |
| 31 | |
| 32 | protected function getTermSearchResult( |
| 33 | array $sourceData, |
| 34 | Term $matchedTerm, |
| 35 | string $matchedTermType, |
| 36 | ?Term $displayLabel, |
| 37 | ?Term $displayDescription |
| 38 | ): ?TermSearchResult { |
| 39 | try { |
| 40 | $entityId = $this->idParser->parse( $sourceData['title'] ); |
| 41 | } catch ( EntityIdParsingException ) { |
| 42 | // Can not parse entity ID - skip it |
| 43 | return null; |
| 44 | } |
| 45 | |
| 46 | return new TermSearchResult( |
| 47 | $matchedTerm, $matchedTermType, $entityId, $displayLabel, |
| 48 | $displayDescription |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | } |