/** * @inheritdoc */ public function behaviors() { return ['search' => ['class' => SearchBehavior::className(), 'searchScope' => function ($model) { /** @var \yii\db\ActiveQuery $model */ $model->select(['author', 'content', 'id']); $model->andWhere(['indexed' => true]); }, 'searchFields' => function ($model) { /** @var self $model */ return [['name' => 'title', 'value' => $model->author], ['name' => 'body', 'value' => strip_tags($model->content), 'type' => SearchBehavior::FIELD_TEXT], ['name' => 'url', 'value' => $model->id, 'type' => SearchBehavior::FIELD_KEYWORD]]; }]]; }
/** * @inheritdoc * * [ * 'class' => TimestampBehavior::className(), * 'createdAtAttribute' => 'created_at', * 'updatedAtAttribute' => 'updated_at', * 'value' => function() { * return date('U'); // unix timestamp * }, * ] */ public function behaviors() { return ['timestamp' => ['class' => TimestampBehavior::className()], 'search' => ['class' => SearchBehavior::className(), 'searchScope' => function ($model) { /** @var \yii\db\ActiveQuery $model */ $model->select(['id', 'title', 'anons', 'content']); $model->andWhere(['publish_status' => [self::STATUS_PUBLISH, self::STATUS_ARCHIVE]]); }, 'searchFields' => function ($model) { /** @var self $model */ return [['name' => 'title', 'value' => $model->title, 'type' => SearchBehavior::FIELD_TEXT], ['name' => 'body', 'value' => strip_tags(Html::decode(Markdown::convert($model->anons))), 'type' => SearchBehavior::FIELD_TEXT], ['name' => 'url', 'value' => '/blog/default/' . $model->id, 'type' => SearchBehavior::FIELD_KEYWORD], ['name' => 'content', 'value' => Markdown::convert($model->content), 'type' => SearchBehavior::FIELD_UNSTORED]]; }]]; }