/** * @param ShopIndex $index * @param ProgressHelperInterface $progress */ public function populate(ShopIndex $index, ProgressHelperInterface $progress) { $ids = $this->getBlogIds($index->getShop()); $progress->start(count($ids), 'Indexing blog'); $chunks = array_chunk($ids, 100); foreach ($chunks as $chunk) { $this->index($index, $chunk); $progress->advance(100); } $progress->finish(); }
/** * @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]); }
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())]); } }