1. Go to this page and download the library: Download samman/yii2-solr library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
public function solrFields(): array
{
return ArrayHelper::merge($this->fields(), [
'book_author_name' => function () {
return $this->author->id;
},
'stock' => function () {
return $this->quantity > 0;
}
]);
}
Yii::$app->solr->createCollection(); // Create a new collection
Yii::$app->solr->dropCollection(); // Drop existing collection
Yii::$app->solr->defineSchema(); // Define the collection schema