/** * Adds Searchable object to algolia index and makes the necessary assertions. * * @param SearchableInterface $searchableObject * * @return \AlgoliaSearch\Index */ private function addSearchableObjectToIndex($searchableObject) { $indexName = $searchableObject->getIndices()[0]; $pushResponse = $this->algoliaManager->pushToIndices($searchableObject); $this->assertArrayHasKey('objectID', $pushResponse[$indexName]); $this->assertArrayHasKey('updatedAt', $pushResponse[$indexName]); $this->assertEquals("{$searchableObject->getObjectID()}", $pushResponse[$indexName]['objectID']); $index = $this->algoliaManager->initIndex($indexName); $index->waitTask($pushResponse[$indexName]['taskID']); return $index; }
/** * Initializes indices for the given SearchableModel. * * @param SearchableInterface $searchableModel * * @return Index[] */ private function initIndices(SearchableInterface $searchableModel) { $indexNames = $searchableModel->getIndices(); $indices = array_map(function ($indexName) { if ($this->env !== null) { $indexName = $this->env . '_' . $indexName; } return $this->initIndex($indexName); }, $indexNames); return $indices; }