These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\SearchBundle\Search; |
||
4 | |||
5 | use Kunstmaan\SearchBundle\Provider\SearchProviderChainInterface; |
||
6 | use Kunstmaan\SearchBundle\Provider\SearchProviderInterface; |
||
7 | |||
8 | /** |
||
9 | * Search class which will delegate to the active SearchProvider |
||
10 | * The active SearchProvider can be overridden by overriding the "kunstmaan_search.search" parameter |
||
11 | */ |
||
12 | class Search implements SearchProviderInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var SearchProviderChainInterface |
||
16 | */ |
||
17 | private $searchProviderChain; |
||
18 | |||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | private $indexNamePrefix; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | private $activeProvider; |
||
28 | |||
29 | /** |
||
30 | * @param SearchProviderChainInterface $searchProviderChain |
||
31 | * @param string $indexNamePrefix |
||
32 | * @param string $activeProvider |
||
33 | */ |
||
34 | public function __construct(SearchProviderChainInterface $searchProviderChain, $indexNamePrefix, $activeProvider) |
||
35 | { |
||
36 | $this->searchProviderChain = $searchProviderChain; |
||
37 | $this->indexNamePrefix = $indexNamePrefix; |
||
38 | $this->activeProvider = $activeProvider; |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Get the current active SearchProvider |
||
43 | * |
||
44 | * @return SearchProviderInterface |
||
45 | */ |
||
46 | public function getActiveProvider() |
||
47 | { |
||
48 | return $this->searchProviderChain->getProvider($this->activeProvider); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | public function createIndex($indexName) |
||
0 ignored issues
–
show
|
|||
55 | { |
||
56 | return $this->getActiveProvider()->createIndex($this->indexNamePrefix . $indexName); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | public function getIndex($indexName) |
||
63 | { |
||
64 | return $this->getActiveProvider()->getIndex($this->indexNamePrefix . $indexName); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | */ |
||
70 | public function getClient() |
||
71 | { |
||
72 | return $this->getActiveProvider()->getClient(); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * {@inheritdoc} |
||
77 | */ |
||
78 | View Code Duplication | public function createDocument($uid, $document, $indexName = '', $indexType = '') |
|
79 | { |
||
80 | $indexName = strtolower($indexName); |
||
81 | |||
82 | return $this->getActiveProvider()->createDocument( |
||
83 | $uid, |
||
84 | $document, |
||
85 | $this->indexNamePrefix . $indexName, |
||
86 | $indexType |
||
87 | ); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | View Code Duplication | public function addDocument($uid, $document, $indexType, $indexName) |
|
94 | { |
||
95 | $indexName = strtolower($indexName); |
||
96 | |||
97 | return $this->getActiveProvider()->addDocument( |
||
98 | $this->indexNamePrefix . $indexName, |
||
99 | $indexType, |
||
100 | $document, |
||
101 | $uid |
||
102 | ); |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * {@inheritdoc} |
||
107 | */ |
||
108 | public function addDocuments($documents, $indexName = '', $indexType = '') |
||
109 | { |
||
110 | $indexName = strtolower($indexName); |
||
111 | |||
112 | return $this->getActiveProvider()->addDocuments($documents, $indexName, $indexType); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | public function deleteDocument($indexName, $indexType, $uid) |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
119 | { |
||
120 | $indexName = strtolower($indexName); |
||
121 | |||
122 | return $this->getActiveProvider()->deleteDocument($this->indexNamePrefix . $indexName, $indexType, $uid); |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * {@inheritdoc} |
||
127 | */ |
||
128 | public function deleteDocuments($indexName, $indexType, array $ids) |
||
129 | { |
||
130 | $indexName = strtolower($indexName); |
||
131 | |||
132 | return $this->getActiveProvider()->deleteDocuments($this->indexNamePrefix . $indexName, $indexType, $ids); |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * {@inheritdoc} |
||
137 | */ |
||
138 | public function deleteIndex($indexName) |
||
139 | { |
||
140 | $indexName = strtolower($indexName); |
||
141 | |||
142 | return $this->getActiveProvider()->deleteIndex($this->indexNamePrefix . $indexName); |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * {@inheritdoc} |
||
147 | */ |
||
148 | public function getName() |
||
149 | { |
||
150 | return 'Search'; |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * Get the prefix for the index' name |
||
155 | * |
||
156 | * @return string |
||
157 | */ |
||
158 | public function getIndexNamePrefix() |
||
159 | { |
||
160 | return $this->indexNamePrefix; |
||
161 | } |
||
162 | } |
||
163 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.