Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
77.78% |
7 / 9 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
EntityElasticTermResult | |
77.78% |
7 / 9 |
|
50.00% |
1 / 2 |
3.10 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
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 | private EntityIdParser $idParser; |
24 | |
25 | public function __construct( |
26 | EntityIdParser $idParser, |
27 | array $searchLanguageCodes, |
28 | string $highlightSubField, |
29 | TermLanguageFallbackChain $displayFallbackChain |
30 | ) { |
31 | parent::__construct( $searchLanguageCodes, $displayFallbackChain, $highlightSubField ); |
32 | $this->idParser = $idParser; |
33 | } |
34 | |
35 | protected function getTermSearchResult( |
36 | array $sourceData, |
37 | Term $matchedTerm, |
38 | string $matchedTermType, |
39 | ?Term $displayLabel, |
40 | ?Term $displayDescription |
41 | ): ?TermSearchResult { |
42 | try { |
43 | $entityId = $this->idParser->parse( $sourceData['title'] ); |
44 | } catch ( EntityIdParsingException ) { |
45 | // Can not parse entity ID - skip it |
46 | return null; |
47 | } |
48 | |
49 | return new TermSearchResult( |
50 | $matchedTerm, $matchedTermType, $entityId, $displayLabel, |
51 | $displayDescription |
52 | ); |
53 | } |
54 | |
55 | } |