1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* WellCommerce Open-Source E-Commerce Platform |
4
|
|
|
* |
5
|
|
|
* This file is part of the WellCommerce package. |
6
|
|
|
* |
7
|
|
|
* (c) Adam Piotrowski <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, |
10
|
|
|
* please view the LICENSE file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace WellCommerce\Bundle\SearchBundle\Manager; |
14
|
|
|
|
15
|
|
|
use Doctrine\Common\Collections\Collection; |
16
|
|
|
use WellCommerce\Component\Search\Adapter\AdapterInterface; |
17
|
|
|
use WellCommerce\Component\Search\Exception\TypeNotFoundException; |
18
|
|
|
use WellCommerce\Component\Search\Model\DocumentInterface; |
19
|
|
|
use WellCommerce\Component\Search\Model\TypeInterface; |
20
|
|
|
use WellCommerce\Component\Search\Request\SearchRequestInterface; |
21
|
|
|
use WellCommerce\Component\Search\Storage\SearchResultStorage; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class SearchManager |
25
|
|
|
* |
26
|
|
|
* @author Adam Piotrowski <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
final class SearchManager implements SearchManagerInterface |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var Collection |
32
|
|
|
*/ |
33
|
|
|
private $types; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var SearchResultStorage |
37
|
|
|
*/ |
38
|
|
|
private $storage; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var AdapterInterface |
42
|
|
|
*/ |
43
|
|
|
private $adapter; |
44
|
|
|
|
45
|
|
|
public function __construct(Collection $types, SearchResultStorage $storage, AdapterInterface $adapter) |
46
|
|
|
{ |
47
|
|
|
$this->types = $types; |
48
|
|
|
$this->storage = $storage; |
49
|
|
|
$this->adapter = $adapter; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function search(SearchRequestInterface $request): array |
53
|
|
|
{ |
54
|
|
|
$result = $this->adapter->search($request); |
55
|
|
|
|
56
|
|
|
$this->storage->setResult($result); |
57
|
|
|
|
58
|
|
|
return $result; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function addDocument(DocumentInterface $document) |
62
|
|
|
{ |
63
|
|
|
return $this->adapter->addDocument($document); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function addDocuments(Collection $documents, string $locale, string $type) |
67
|
|
|
{ |
68
|
|
|
return $this->adapter->addDocuments($documents, $locale, $type); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function updateDocument(DocumentInterface $document) |
72
|
|
|
{ |
73
|
|
|
return $this->adapter->addDocument($document); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function removeDocument(DocumentInterface $document) |
77
|
|
|
{ |
78
|
|
|
return $this->adapter->addDocument($document); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function createIndex(string $locale, string $type) |
82
|
|
|
{ |
83
|
|
|
$this->adapter->createIndex($locale, $type); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function flushIndex(string $locale, string $type) |
87
|
|
|
{ |
88
|
|
|
$this->adapter->flushIndex($locale, $type); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function removeIndex(string $locale, string $type) |
92
|
|
|
{ |
93
|
|
|
$this->adapter->removeIndex($locale, $type); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function getType(string $type): TypeInterface |
97
|
|
|
{ |
98
|
|
|
if (false === $this->types->containsKey($type)) { |
99
|
|
|
throw new TypeNotFoundException($type, $this->types->getKeys()); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $this->types->get($type); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function getTypes(): Collection |
106
|
|
|
{ |
107
|
|
|
return $this->types; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|