7
7
use Illuminate \Database \Eloquent \Collection ;
8
8
use Illuminate \Database \Eloquent \Model ;
9
9
use Illuminate \Support \Arr ;
10
+ use Illuminate \Support \LazyCollection ;
10
11
use Laravel \Scout \Builder ;
11
12
use Laravel \Scout \Engines \Engine ;
12
13
use ScoutEngines \Postgres \TsQuery \PhraseToTsQuery ;
@@ -76,14 +77,14 @@ public function update($models)
76
77
* Perform update of the given model.
77
78
*
78
79
* @param \Illuminate\Database\Eloquent\Model $model
79
- * @return bool
80
+ * @return bool|int
80
81
*/
81
82
protected function performUpdate (Model $ model )
82
83
{
83
- $ data = collect ([$ this ->getIndexColumn ($ model ) => $ this ->toVector ($ model )]);
84
+ $ data = collect (/** @scrutinizer ignore-type */ [$ this ->getIndexColumn ($ model ) => $ this ->toVector ($ model )]);
84
85
85
86
$ query = $ this ->database
86
- ->table ($ model ->searchableAs ())
87
+ ->table (/** @scrutinizer ignore-type */ $ model ->searchableAs ())
87
88
->where ($ model ->getKeyName (), '= ' , $ model ->getKey ());
88
89
89
90
if (method_exists ($ model , 'searchableAdditionalArray ' )) {
@@ -109,12 +110,12 @@ protected function performUpdate(Model $model)
109
110
*/
110
111
protected function toVector (Model $ model )
111
112
{
112
- $ fields = collect ($ model ->toSearchableArray ())
113
+ $ fields = collect (/** @scrutinizer ignore-type */ $ model ->toSearchableArray ())
113
114
->map (function ($ value ) {
114
115
return $ value === null ? '' : $ value ;
115
116
});
116
117
117
- $ bindings = collect ([]);
118
+ $ bindings = collect (/** @scrutinizer ignore-type */ []);
118
119
119
120
// The choices of parser, dictionaries and which types of tokens to index are determined
120
121
// by the selected text search configuration which can be set globally in config/scout.php
@@ -123,7 +124,7 @@ protected function toVector(Model $model)
123
124
$ vector = 'to_tsvector(COALESCE(?, get_current_ts_config()), ?) ' ;
124
125
125
126
$ select = $ fields ->map (function ($ value , $ key ) use ($ model , $ vector , $ bindings ) {
126
- $ bindings ->push ($ this ->searchConfig ($ model ) ?: null )
127
+ $ bindings ->push (/** @scrutinizer ignore-type */ $ this ->searchConfig ($ model ) ?: null )
127
128
->push ($ value );
128
129
129
130
// Set a field weight if it was specified in Model's searchableOptions()
@@ -225,7 +226,7 @@ protected function performSearch(Builder $builder, $perPage = 0, $page = 1)
225
226
226
227
// Build the SQL query
227
228
$ query = $ this ->database
228
- ->table ($ builder ->index ?: $ builder ->model ->searchableAs ())
229
+ ->table (/** @scrutinizer ignore-type */ $ builder ->index ?: $ builder ->model ->searchableAs ())
229
230
->select ($ builder ->model ->getKeyName ())
230
231
->selectRaw ("{$ this ->rankingExpression ($ builder ->model , $ indexColumn )} AS rank " )
231
232
->selectRaw ('COUNT(*) OVER () AS total_count ' )
@@ -240,7 +241,7 @@ protected function performSearch(Builder $builder, $perPage = 0, $page = 1)
240
241
if (! $ this ->isExternalIndex ($ builder ->model )) {
241
242
// and the model uses soft deletes we need to exclude trashed rows
242
243
if ($ this ->usesSoftDeletes ($ builder ->model )) {
243
- $ query ->whereNull ($ builder ->model ->getDeletedAtColumn ());
244
+ $ query ->whereNull (/** @scrutinizer ignore-type */ $ builder ->model ->getDeletedAtColumn ());
244
245
}
245
246
}
246
247
@@ -407,7 +408,7 @@ protected function connect()
407
408
*/
408
409
protected function rankingExpression (Model $ model , $ indexColumn )
409
410
{
410
- $ args = collect ([$ indexColumn , '"tsquery" ' ]);
411
+ $ args = collect (/** @scrutinizer ignore-type */ [$ indexColumn , '"tsquery" ' ]);
411
412
412
413
if ($ weights = $ this ->rankWeights ($ model )) {
413
414
$ args ->prepend ("' $ weights' " );
@@ -426,15 +427,15 @@ protected function rankingExpression(Model $model, $indexColumn)
426
427
* Get rank function.
427
428
*
428
429
* @param \Illuminate\Database\Eloquent\Model $model
429
- * @return int
430
+ * @return string
430
431
*/
431
432
protected function rankFunction (Model $ model )
432
433
{
433
434
$ default = 'ts_rank ' ;
434
435
435
436
$ function = $ this ->option ($ model , 'rank.function ' , $ default );
436
437
437
- return collect (['ts_rank ' , 'ts_rank_cd ' ])->contains ($ function ) ? $ function : $ default ;
438
+ return collect (/** @scrutinizer ignore-type */ ['ts_rank ' , 'ts_rank_cd ' ])->contains ($ function ) ? $ function : $ default ;
438
439
}
439
440
440
441
/**
@@ -448,7 +449,7 @@ protected function rankFieldWeightLabel(Model $model, $field)
448
449
{
449
450
$ label = $ this ->option ($ model , "rank.fields. $ field " );
450
451
451
- return collect (['A ' , 'B ' , 'C ' , 'D ' ])
452
+ return collect (/** @scrutinizer ignore-type */ ['A ' , 'B ' , 'C ' , 'D ' ])
452
453
->contains ($ label ) ? $ label : '' ;
453
454
}
454
455
@@ -535,7 +536,7 @@ protected function option(Model $model, $key, $default = null)
535
536
536
537
$ options = $ model ->searchableOptions () ?: [];
537
538
538
- return Arr::get ($ options , $ key , $ default );
539
+ return Arr::get (/** @scrutinizer ignore-type */ $ options , $ key , $ default );
539
540
}
540
541
541
542
/**
@@ -595,7 +596,7 @@ public function flush($model)
595
596
$ indexColumn = $ this ->getIndexColumn ($ model );
596
597
597
598
$ this ->database
598
- ->table ($ model ->searchableAs ())
599
+ ->table (/** @scrutinizer ignore-type */ $ model ->searchableAs ())
599
600
->update ([$ indexColumn => null ]);
600
601
}
601
602
}
0 commit comments