Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 34 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| EntitySearchHelperFactory | |
0.00% |
0 / 34 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| newFromGlobalState | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| newItemPropertySearchHelper | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Wikibase\Search\Elastic; |
| 4 | |
| 5 | use MediaWiki\Language\Language; |
| 6 | use MediaWiki\Request\WebRequest; |
| 7 | use Wikibase\DataModel\Entity\EntityIdParser; |
| 8 | use Wikibase\DataModel\Services\Lookup\EntityLookup; |
| 9 | use Wikibase\DataModel\Services\Lookup\TermLookup; |
| 10 | use Wikibase\Lib\LanguageFallbackChainFactory; |
| 11 | use Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookup; |
| 12 | use Wikibase\Repo\Api\CombinedEntitySearchHelper; |
| 13 | use Wikibase\Repo\Api\EntityIdSearchHelper; |
| 14 | use Wikibase\Repo\Api\EntitySearchHelper; |
| 15 | use Wikibase\Repo\WikibaseRepo; |
| 16 | |
| 17 | /** |
| 18 | * @license GPL-2.0-or-later |
| 19 | */ |
| 20 | class EntitySearchHelperFactory { |
| 21 | private EntityIdParser $entityIdParser; |
| 22 | private LanguageFallbackChainFactory $languageFallbackChainFactory; |
| 23 | private EntityLookup $entityLookup; |
| 24 | private TermLookup $termLookup; |
| 25 | private array $enabledEntityTypes; |
| 26 | private array $contentModelMappings; |
| 27 | |
| 28 | public function __construct( |
| 29 | EntityIdParser $entityIdParser, |
| 30 | LanguageFallbackChainFactory $languageFallbackChainFactory, |
| 31 | EntityLookup $entityLookup, |
| 32 | TermLookup $termLookup, |
| 33 | array $enabledEntityTypes, |
| 34 | array $contentModelMappings |
| 35 | ) { |
| 36 | $this->entityIdParser = $entityIdParser; |
| 37 | $this->languageFallbackChainFactory = $languageFallbackChainFactory; |
| 38 | $this->entityLookup = $entityLookup; |
| 39 | $this->termLookup = $termLookup; |
| 40 | $this->enabledEntityTypes = $enabledEntityTypes; |
| 41 | $this->contentModelMappings = $contentModelMappings; |
| 42 | } |
| 43 | |
| 44 | public static function newFromGlobalState(): self { |
| 45 | return new self( |
| 46 | WikibaseRepo::getEntityIdParser(), |
| 47 | WikibaseRepo::getLanguageFallbackChainFactory(), |
| 48 | WikibaseRepo::getEntityLookup(), |
| 49 | WikibaseRepo::getTermLookup(), |
| 50 | WikibaseRepo::getEnabledEntityTypes(), |
| 51 | WikibaseRepo::getContentModelMappings() |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | public function newItemPropertySearchHelper( WebRequest $request, Language $resultLanguage ): EntitySearchHelper { |
| 56 | return new CombinedEntitySearchHelper( |
| 57 | [ |
| 58 | new EntityIdSearchHelper( |
| 59 | $this->entityLookup, |
| 60 | $this->entityIdParser, |
| 61 | new LanguageFallbackLabelDescriptionLookup( |
| 62 | $this->termLookup, |
| 63 | $this->languageFallbackChainFactory->newFromLanguage( $resultLanguage ) |
| 64 | ), |
| 65 | $this->enabledEntityTypes |
| 66 | ), |
| 67 | new EntitySearchElastic( |
| 68 | $this->languageFallbackChainFactory, |
| 69 | $this->entityIdParser, |
| 70 | $resultLanguage, |
| 71 | $this->contentModelMappings, |
| 72 | $request |
| 73 | ), |
| 74 | ] |
| 75 | ); |
| 76 | } |
| 77 | |
| 78 | } |