From bc667e0abeea9e471614004658a08bd3a3ddecb1 Mon Sep 17 00:00:00 2001 From: Vuong Minh Date: Tue, 16 Apr 2019 22:51:10 +0700 Subject: [PATCH] Release version 1.0.1 --- README.md | 2 +- src/Searchable.php | 21 ++++++--------------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 97e71a0..77bcf8d 100644 --- a/README.md +++ b/README.md @@ -392,7 +392,7 @@ $posts = \app\models\Post::search('vxm')->joinWith('category')->andWhere(Categor ### Search mode -You can choice a `boolean` or `fuzzy` search mode: +You can choice a `boolean` or `fuzzy` search mode as a second parameter if not set `defaultSearchMode` of `Searchable` component will be use: ```php $posts = \app\models\Post::search('vxm', 'fuzzy', ['fuzziness' => true])->all(); diff --git a/src/Searchable.php b/src/Searchable.php index 6048bdd..2277eb7 100644 --- a/src/Searchable.php +++ b/src/Searchable.php @@ -208,31 +208,22 @@ public function upsert($models, array $config = []): void { $models = is_array($models) ? $models : [$models]; /** @var \yii\db\ActiveRecord $modelClass */ - try { - $modelClass = get_class(current($models)); - } catch (\Throwable $t) { - var_dump(current($models)); - die; - } + $modelClass = get_class(current($models)); $this->initIndex($modelClass, $config); $tnt = $this->createTNTSearch($modelClass::getDb(), $config); $tnt->selectIndex("{$modelClass::searchableIndex()}.index"); $index = $tnt->getIndex(); $index->setPrimaryKey($modelClass::searchableKey()); + $index->indexBeginTransaction(); foreach ($models as $model) { - /** @var \yii\db\ActiveRecord $model */ - $data = $model->toSearchableArray(); - - if (empty($data)) { - return; + if ($data = $model->toSearchableArray()) { + $index->update($model->getSearchableKey(), $data); } - - $index->indexBeginTransaction(); - $index->update($model->getSearchableKey(), $data); - $index->indexEndTransaction(); } + + $index->indexEndTransaction(); } /**