S
S
Sergey Erin2021-04-29 16:38:32
Yii
Sergey Erin, 2021-04-29 16:38:32

How to update search index when data changes?

Hello! The site uses this component to organize post searches. There was a need to update some url records in the database. As a result, now these updated records are loaded with old links when searching. Is it possible to somehow partially update the search index? In the model in the method behaviorslike this:

'searchScope' => function ($model) {
    /** @var \yii\db\ActiveQuery $model */
    $model->select(['name', 'text', 'id', 'image', 'slug']);
},
'searchFields' => function ($model) {
    /** @var self $model */
    return [
        ['name' => 'name', 'value' => $model->name],
        ['name' => 'text', 'value' => strip_tags($model->text)],
        ['name' => 'img', 'value' => $model->image, 'type' => SearchBehavior::FIELD_UNINDEXED],
        ['name' => 'url', 'value' => $model->slug, 'type' => SearchBehavior::FIELD_UNINDEXED],
    ];
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question