3
3
namespace Swis \Laravel \Fulltext ;
4
4
5
5
use Illuminate \Database \Eloquent \Builder ;
6
+ use Illuminate \Database \Eloquent \Model ;
6
7
use Illuminate \Support \Collection ;
7
8
use Illuminate \Support \Facades \Config ;
8
9
@@ -17,6 +18,10 @@ public function run(string $search): Collection
17
18
18
19
public function runForClass (string $ search , string $ class ): Collection
19
20
{
21
+ if (!is_subclass_of ($ class , Model::class)) {
22
+ return new Collection ();
23
+ }
24
+
20
25
$ query = $ this ->searchQuery ($ search );
21
26
$ query ->where ('indexable_type ' , (new $ class )->getMorphClass ());
22
27
@@ -35,8 +40,8 @@ public function searchQuery(string $search): Builder
35
40
$ termsMatch = $ terms ->implode (' ' );
36
41
}
37
42
38
- $ titleWeight = str_replace (', ' , '. ' , sprintf ('%f ' , Config::get ('laravel-fulltext.weight.title ' , 1.5 )));
39
- $ contentWeight = str_replace (', ' , '. ' , sprintf ('%f ' , Config::get ('laravel-fulltext.weight.content ' , 1.0 )));
43
+ $ titleWeight = str_replace (', ' , '. ' , sprintf ('%f ' , Config::float ('laravel-fulltext.weight.title ' , 1.5 )));
44
+ $ contentWeight = str_replace (', ' , '. ' , sprintf ('%f ' , Config::float ('laravel-fulltext.weight.content ' , 1.0 )));
40
45
41
46
$ query = IndexedRecord::query ()
42
47
->whereRaw ('MATCH (indexed_title, indexed_content) AGAINST (? IN BOOLEAN MODE) ' , [$ termsBool ])
@@ -45,9 +50,9 @@ public function searchQuery(string $search): Builder
45
50
' .$ contentWeight .' * (MATCH (indexed_title, indexed_content) AGAINST (?))
46
51
) DESC ' ,
47
52
[$ termsMatch , $ termsMatch ])
48
- ->limit (Config::get ('laravel-fulltext.limit-results ' ));
53
+ ->limit (Config::integer ('laravel-fulltext.limit-results ' ));
49
54
50
- if (Config::get ('laravel-fulltext.exclude_feature_enabled ' )) {
55
+ if (Config::boolean ('laravel-fulltext.exclude_feature_enabled ' )) {
51
56
$ query ->with (['indexable ' => function ($ query ) {
52
57
$ query ->where (Config::get ('laravel-fulltext.exclude_records_column_name ' ), '= ' , true );
53
58
}]);
0 commit comments