/** * @param ShopIndex $index * @param string[] $numbers * @return \string[] */ public function indexProducts(ShopIndex $index, $numbers) { if (empty($numbers)) { return; } $products = $this->provider->get($index->getShop(), $numbers); $remove = array_diff($numbers, array_keys($products)); $documents = []; foreach ($products as $product) { $documents[] = ['index' => ['_id' => $product->getNumber()]]; $documents[] = $product; } foreach ($remove as $number) { $documents[] = ['delete' => ['_id' => $number]]; } $this->client->bulk(['index' => $index->getName(), 'type' => ProductMapping::TYPE, 'body' => $documents]); }
/** * @param ShopIndex $index * @param int[] $groupIds */ public function indexProperties(ShopIndex $index, $groupIds) { if (empty($groupIds)) { return; } /** @var Group[] $properties */ $properties = $this->provider->get($index->getShop(), $groupIds); $remove = array_diff($groupIds, array_keys($properties)); $documents = []; foreach ($properties as $property) { $documents[] = ['index' => ['_id' => $property->getId()]]; $documents[] = $property; } foreach ($remove as $id) { $documents[] = ['delete' => ['_id' => $id]]; } $this->client->bulk(['index' => $index->getName(), 'type' => PropertyMapping::TYPE, 'body' => $documents]); }
/** * @param ShopIndex $index * @param int[] $ids */ public function index(ShopIndex $index, $ids) { if (empty($ids)) { return; } $blog = $this->provider->get($ids); $remove = array_diff($ids, array_keys($blog)); $documents = []; foreach ($blog as $row) { $documents[] = ['index' => ['_id' => $row->getId()]]; $documents[] = $row; } foreach ($remove as $id) { $documents[] = ['delete' => ['_id' => $id]]; } if (empty($documents)) { return; } $this->client->bulk(['index' => $index->getName(), 'type' => 'blog', 'body' => $documents]); }
public function synchronize(ShopIndex $shopIndex, $backlogs) { $ids = []; foreach ($backlogs as $backlog) { switch ($backlog->getEvent()) { case ORMBacklogSubscriber::EVENT_BLOG_UPDATED: case ORMBacklogSubscriber::EVENT_BLOG_DELETED: case ORMBacklogSubscriber::EVENT_BLOG_INSERTED: $payload = $backlog->getPayload(); $ids[] = $payload['id']; break; default: continue; } } $blogIds = $this->filterShopBlog($shopIndex->getShop(), $ids); if (empty($blogIds)) { return; } $this->indexer->index($shopIndex, $blogIds); }
/** * @param ShopIndex $index */ private function updateMapping(ShopIndex $index) { foreach ($this->mappings as $mapping) { $this->client->indices()->putMapping(['index' => $index->getName(), 'type' => $mapping->getType(), 'body' => $mapping->get($index->getShop())]); } }