28 private $indexStructure;
38 private $indexNameResolver;
58 private $scopeResolver;
71 ElasticsearchAdapter $adapter,
76 $batchSize = self::DEFAULT_BATCH_SIZE
78 $this->indexStructure = $indexStructure;
80 $this->indexNameResolver = $indexNameResolver;
81 $this->batch = $batch;
83 $this->batchSize = $batchSize;
84 $this->scopeResolver = $scopeResolver;
90 public function saveIndex($dimensions, \Traversable $documents)
92 $dimension = current($dimensions);
93 $scopeId = $this->scopeResolver->getScope($dimension->getValue())->getId();
94 foreach ($this->batch->getItems($documents, $this->batchSize) as $documentsBatch) {
95 $docs = $this->adapter->prepareDocsPerStore($documentsBatch, $scopeId);
96 $this->adapter->addDocs($docs, $scopeId, $this->getIndexerId());
98 $this->adapter->updateAlias($scopeId, $this->getIndexerId());
107 $dimension = current($dimensions);
108 $scopeId = $this->scopeResolver->getScope($dimension->getValue())->getId();
110 foreach ($documents as $document) {
111 $documentIds[$document] = $document;
113 $this->adapter->deleteDocs($documentIds, $scopeId, $this->getIndexerId());
122 $this->indexStructure->delete($this->getIndexerId(), $dimensions);
123 $this->indexStructure->create($this->getIndexerId(), [], $dimensions);
132 return $this->adapter->ping();
140 private function getIndexerId()
142 return $this->indexNameResolver->getIndexMapping($this->data[
'indexer_id']);
__construct(IndexStructureInterface $indexStructure, ElasticsearchAdapter $adapter, IndexNameResolver $indexNameResolver, Batch $batch, ScopeResolverInterface $scopeResolver, array $data=[], $batchSize=self::DEFAULT_BATCH_SIZE)
deleteIndex($dimensions, \Traversable $documents)
isAvailable($dimensions=[])
saveIndex($dimensions, \Traversable $documents)