@@ -221,8 +221,8 @@ protected function performSearch(Builder $builder, array $options = [])
221
221
->cloneWithoutBindings (['order ' ]);
222
222
$ results = ['nbHits ' => $ countQuery ->count ($ countQuery ->getConnection ()->raw ('distinct record_id ' ))];
223
223
224
- // Performing the search itself :
225
- $ results ['hits ' ] = $ query ->with ('record ' )-> get ( );
224
+ // Preparing the actual query :
225
+ $ results ['query ' ] = $ query ->with ('record ' );
226
226
227
227
return $ results ;
228
228
}
@@ -235,7 +235,19 @@ protected function performSearch(Builder $builder, array $options = [])
235
235
*/
236
236
public function mapIds ($ results )
237
237
{
238
- return $ results ['hits ' ]->pluck ('record_id ' )->values ();
238
+ return $ results ['query ' ]->pluck ('record_id ' )->values ();
239
+ }
240
+
241
+ /**
242
+ * Extract the Model from the search hit.
243
+ *
244
+ * @param SearchIndex $hit
245
+ * @return \Illuminate\Database\Eloquent\Model
246
+ */
247
+ protected function getRecord ($ hit )
248
+ {
249
+ $ hit ->record ->_score = $ hit ->_score ;
250
+ return $ hit ->record ;
239
251
}
240
252
241
253
/**
@@ -248,9 +260,8 @@ public function mapIds($results)
248
260
*/
249
261
public function map (Builder $ builder , $ results , $ model )
250
262
{
251
- $ models = $ results ['hits ' ]->map (function ($ hit ) {
252
- $ hit ->record ->_score = $ hit ->_score ;
253
- return $ hit ->record ;
263
+ $ models = $ results ['query ' ]->get ()->map (function ($ hit ) {
264
+ return $ this ->getRecord ($ hit );
254
265
})->all ();
255
266
return $ model ->newCollection ($ models );
256
267
}
@@ -265,11 +276,9 @@ public function map(Builder $builder, $results, $model)
265
276
*/
266
277
public function lazyMap (Builder $ builder , $ results , $ model )
267
278
{
268
- $ models = $ results ['hits ' ]->map (function ($ hit ) {
269
- $ hit ->record ->_score = $ hit ->_score ;
270
- return $ hit ->record ;
271
- })->all ();
272
- return new LazyCollection ($ models );
279
+ return $ results ['query ' ]->lazy ()->map (function ($ hit ) {
280
+ return $ this ->getRecord ($ hit );
281
+ });
273
282
}
274
283
275
284
/**
0 commit comments