@@ -72,7 +72,10 @@ public function update($models)
72
72
$ model ->scoutMetadata (),
73
73
[$ model ->getScoutKeyName () => $ model ->getScoutKey ()],
74
74
);
75
- })->filter ()->values ()->all ();
75
+ })
76
+ ->filter ()
77
+ ->values ()
78
+ ->all ();
76
79
77
80
if (! empty ($ objects )) {
78
81
$ index ->addDocuments ($ objects , $ models ->first ()->getScoutKeyName ());
@@ -176,19 +179,20 @@ protected function performSearch(Builder $builder, array $searchParams = [])
176
179
*/
177
180
protected function filters (Builder $ builder )
178
181
{
179
- $ filters = collect ($ builder ->wheres )->map (function ($ value , $ key ) {
180
- if (is_bool ($ value )) {
181
- return sprintf ('%s=%s ' , $ key , $ value ? 'true ' : 'false ' );
182
- }
182
+ $ filters = collect ($ builder ->wheres )
183
+ ->map (function ($ value , $ key ) {
184
+ if (is_bool ($ value )) {
185
+ return sprintf ('%s=%s ' , $ key , $ value ? 'true ' : 'false ' );
186
+ }
183
187
184
- if (is_null ($ value )) {
185
- return sprintf ('%s %s ' , $ key , 'IS NULL ' );
186
- }
188
+ if (is_null ($ value )) {
189
+ return sprintf ('%s %s ' , $ key , 'IS NULL ' );
190
+ }
187
191
188
- return is_numeric ($ value )
189
- ? sprintf ('%s=%s ' , $ key , $ value )
190
- : sprintf ('%s="%s" ' , $ key , $ value );
191
- });
192
+ return is_numeric ($ value )
193
+ ? sprintf ('%s=%s ' , $ key , $ value )
194
+ : sprintf ('%s="%s" ' , $ key , $ value );
195
+ });
192
196
193
197
$ whereInOperators = [
194
198
'whereIns ' => 'IN ' ,
@@ -219,9 +223,9 @@ protected function filters(Builder $builder)
219
223
*/
220
224
protected function buildSortFromOrderByClauses (Builder $ builder ): array
221
225
{
222
- return collect ($ builder ->orders )-> map ( function ( array $ order ) {
223
- return $ order ['column ' ].': ' .$ order ['direction ' ];
224
- }) ->toArray ();
226
+ return collect ($ builder ->orders )
227
+ -> map ( fn ( array $ order) => $ order ['column ' ].': ' .$ order ['direction ' ])
228
+ ->toArray ();
225
229
}
226
230
227
231
/**
@@ -288,23 +292,21 @@ public function map(Builder $builder, $results, $model)
288
292
289
293
$ objectIdPositions = array_flip ($ objectIds );
290
294
291
- return $ model ->getScoutModelsByIds (
292
- $ builder , $ objectIds
293
- )->filter (function ($ model ) use ($ objectIds ) {
294
- return in_array ($ model ->getScoutKey (), $ objectIds );
295
- })->map (function ($ model ) use ($ results , $ objectIdPositions ) {
296
- $ result = $ results ['hits ' ][$ objectIdPositions [$ model ->getScoutKey ()]] ?? [];
295
+ return $ model ->getScoutModelsByIds ($ builder , $ objectIds )
296
+ ->filter (fn ($ model ) => in_array ($ model ->getScoutKey (), $ objectIds ))
297
+ ->map (function ($ model ) use ($ results , $ objectIdPositions ) {
298
+ $ result = $ results ['hits ' ][$ objectIdPositions [$ model ->getScoutKey ()]] ?? [];
297
299
298
- foreach ($ result as $ key => $ value ) {
299
- if (substr ($ key , 0 , 1 ) === '_ ' ) {
300
- $ model ->withScoutMetadata ($ key , $ value );
300
+ foreach ($ result as $ key => $ value ) {
301
+ if (substr ($ key , 0 , 1 ) === '_ ' ) {
302
+ $ model ->withScoutMetadata ($ key , $ value );
303
+ }
301
304
}
302
- }
303
305
304
- return $ model ;
305
- })-> sortBy ( function ( $ model ) use ( $ objectIdPositions ) {
306
- return $ objectIdPositions [$ model ->getScoutKey ()];
307
- }) ->values ();
306
+ return $ model ;
307
+ })
308
+ -> sortBy ( fn ( $ model ) => $ objectIdPositions [$ model ->getScoutKey ()])
309
+ ->values ();
308
310
}
309
311
310
312
/**
@@ -323,23 +325,22 @@ public function lazyMap(Builder $builder, $results, $model)
323
325
$ objectIds = collect ($ results ['hits ' ])->pluck ($ model ->getScoutKeyName ())->values ()->all ();
324
326
$ objectIdPositions = array_flip ($ objectIds );
325
327
326
- return $ model ->queryScoutModelsByIds (
327
- $ builder , $ objectIds
328
- )->cursor ()->filter (function ($ model ) use ($ objectIds ) {
329
- return in_array ($ model ->getScoutKey (), $ objectIds );
330
- })->map (function ($ model ) use ($ results , $ objectIdPositions ) {
331
- $ result = $ results ['hits ' ][$ objectIdPositions [$ model ->getScoutKey ()]] ?? [];
328
+ return $ model ->queryScoutModelsByIds ($ builder , $ objectIds )
329
+ ->cursor ()
330
+ ->filter (fn ($ model ) => in_array ($ model ->getScoutKey (), $ objectIds ))
331
+ ->map (function ($ model ) use ($ results , $ objectIdPositions ) {
332
+ $ result = $ results ['hits ' ][$ objectIdPositions [$ model ->getScoutKey ()]] ?? [];
332
333
333
- foreach ($ result as $ key => $ value ) {
334
- if (substr ($ key , 0 , 1 ) === '_ ' ) {
335
- $ model ->withScoutMetadata ($ key , $ value );
334
+ foreach ($ result as $ key => $ value ) {
335
+ if (substr ($ key , 0 , 1 ) === '_ ' ) {
336
+ $ model ->withScoutMetadata ($ key , $ value );
337
+ }
336
338
}
337
- }
338
339
339
- return $ model ;
340
- })-> sortBy ( function ( $ model ) use ( $ objectIdPositions ) {
341
- return $ objectIdPositions [$ model ->getScoutKey ()];
342
- }) ->values ();
340
+ return $ model ;
341
+ })
342
+ -> sortBy ( fn ( $ model ) => $ objectIdPositions [$ model ->getScoutKey ()])
343
+ ->values ();
343
344
}
344
345
345
346
/**
0 commit comments