Skip to content

Commit c3ce55b

Browse files
committed
init index on empty collection
#80
1 parent 392dd65 commit c3ce55b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Engines/TNTSearchEngine.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Laravel\Scout\Builder;
77
use Laravel\Scout\Engines\Engine;
88
use TeamTNT\TNTSearch\TNTSearch;
9+
use TeamTNT\TNTSearch\Exceptions\IndexNotFoundException;
910

1011
class TNTSearchEngine extends Engine
1112
{
@@ -81,7 +82,11 @@ public function delete($models)
8182
*/
8283
public function search(Builder $builder)
8384
{
84-
return $this->performSearch($builder);
85+
try {
86+
return $this->performSearch($builder);
87+
} catch (IndexNotFoundException $e) {
88+
$this->initIndex($builder->model);
89+
}
8590
}
8691

8792
/**
@@ -209,4 +214,4 @@ public function initIndex($model)
209214
$indexer->setPrimaryKey($model->getKeyName());
210215
}
211216
}
212-
}
217+
}

0 commit comments

Comments
 (0)