Skip to content

Commit

Permalink
Release version 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
vuongxuongminh committed Apr 16, 2019
1 parent aae9ed8 commit bc667e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
21 changes: 6 additions & 15 deletions src/Searchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down

0 comments on commit bc667e0

Please sign in to comment.