-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathSearchEngineIndexerFactory.php
More file actions
90 lines (79 loc) · 2.88 KB
/
Copy pathSearchEngineIndexerFactory.php
File metadata and controls
90 lines (79 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace Ibexa\Bundle\Core\ApiLoader;
use Ibexa\Bundle\Core\ApiLoader\Exception\InvalidSearchEngine;
use Ibexa\Bundle\Core\ApiLoader\Exception\InvalidSearchEngineIndexer;
use Ibexa\Contracts\Core\Container\ApiLoader\RepositoryConfigurationProviderInterface;
use Ibexa\Core\Search\Common\Indexer;
use Ibexa\Core\Search\Common\Indexer as SearchEngineIndexer;
/**
* The search engine indexer factory.
*/
class SearchEngineIndexerFactory
{
/**
* Hash of registered search engine indexers.
* Key is the search engine identifier, value indexer itself.
*
* @var Indexer[]
*/
protected $searchEngineIndexers = [];
public function __construct(
private readonly RepositoryConfigurationProviderInterface $repositoryConfigurationProvider,
) {}
/**
* Registers $searchEngineIndexer as a valid search engine indexer with identifier $searchEngineIdentifier.
*
* note: It is strongly recommended to register indexer as a lazy service.
*
* @param Indexer $searchEngineIndexer
* @param string $searchEngineIdentifier
*/
public function registerSearchEngineIndexer(
SearchEngineIndexer $searchEngineIndexer,
$searchEngineIdentifier
) {
$this->searchEngineIndexers[$searchEngineIdentifier] = $searchEngineIndexer;
}
/**
* Returns registered search engine indexers.
*
* @return Indexer[]
*/
public function getSearchEngineIndexers()
{
return $this->searchEngineIndexers;
}
/**
* Build search engine indexer identified by its identifier (the "alias" attribute in the service tag),
* resolved for current SiteAccess.
*
* @throws InvalidSearchEngineIndexer
*
* @return Indexer
*/
public function buildSearchEngineIndexer(): SearchEngineIndexer
{
$repositoryConfig = $this->repositoryConfigurationProvider->getRepositoryConfig();
$searchEngineAlias = $repositoryConfig['search']['engine'] ?? null;
if (null === $searchEngineAlias) {
throw new InvalidSearchEngine(
sprintf(
'Ibexa "%s" Repository has no Search Engine configured',
$this->repositoryConfigurationProvider->getCurrentRepositoryAlias()
)
);
}
if (!isset($this->searchEngineIndexers[$searchEngineAlias])) {
throw new InvalidSearchEngineIndexer(
"Invalid search engine '{$searchEngineAlias}'. " .
"Could not find any service tagged with 'ibexa.search.engine.indexer' " .
"with alias '{$searchEngineAlias}'."
);
}
return $this->searchEngineIndexers[$searchEngineAlias];
}
}