예제 #1
0
 /**
  * @param string $className The name of the class which is to be searched.
  * @param string $query
  * @param null|array $searchParameters Optional search parameters given as an associative array.
  *
  * @link https://github.com/algolia/algoliasearch-client-php#search-parameters Allowed search parameters.
  *
  * @return array
  */
 public function search($className, $query, array $searchParameters = null)
 {
     $this->checkImplementsSearchableInterface($className);
     $activeRecord = $this->activeRecordFactory->make($className);
     $response = [];
     /* @var SearchableInterface $activeRecord */
     $indices = $indices = $this->initIndices($activeRecord);
     foreach ($indices as $index) {
         $response[$index->indexName] = $index->search($query, $searchParameters);
     }
     return $response;
 }
 /**
  * @test
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Cannot initiate a class (leinonen\Yii2Algolia\AlgoliaFactory) which doesn't implement \yii\db\ActiveRecordInterface
  */
 public function it_throws_an_error_if_the_class_is_not_instance_of_ActiveRecordInterface()
 {
     $factory = new ActiveRecordFactory();
     $createdActiveRecord = $factory->make(AlgoliaFactory::class);
 }