indexStructure = $indexStructure; $this->adapter = $adapter; $this->indexNameResolver = $indexNameResolver; $this->batch = $batch; $this->data = $data; $this->batchSize = $batchSize; $this->scopeResolver = $scopeResolver; } /** * @inheritdoc */ public function saveIndex($dimensions, \Traversable $documents) { $dimension = current($dimensions); $scopeId = $this->scopeResolver->getScope($dimension->getValue())->getId(); foreach ($this->batch->getItems($documents, $this->batchSize) as $documentsBatch) { $docs = $this->adapter->prepareDocsPerStore($documentsBatch, $scopeId); $this->adapter->addDocs($docs, $scopeId, $this->getIndexerId()); } $this->adapter->updateAlias($scopeId, $this->getIndexerId()); return $this; } /** * @inheritdoc */ public function deleteIndex($dimensions, \Traversable $documents) { $dimension = current($dimensions); $scopeId = $this->scopeResolver->getScope($dimension->getValue())->getId(); $documentIds = []; foreach ($documents as $document) { $documentIds[$document] = $document; } $this->adapter->deleteDocs($documentIds, $scopeId, $this->getIndexerId()); return $this; } /** * @inheritdoc */ public function cleanIndex($dimensions) { $this->indexStructure->delete($this->getIndexerId(), $dimensions); $this->indexStructure->create($this->getIndexerId(), [], $dimensions); return $this; } /** * @inheritdoc */ public function isAvailable($dimensions = []) { return $this->adapter->ping(); } /** * Returns indexer id. * * @return string */ private function getIndexerId() { return $this->indexNameResolver->getIndexMapping($this->data['indexer_id']); } }