backend/helper/scout-sonic-engine/src/SonicEngine.php
/**
     * Map the given results to instances of the given model.
     *
     * @param  \Laravel\Scout\Builder  $builder
     * @param  mixed  $results
     * @param  \Illuminate\Database\Eloquent\Model  $model
     * @return \Illuminate\Database\Eloquent\Collection
     */
Map the given results to instances of the given model.
Map the given results to instances of the given model .
public function map(Builder $builder, $results, $model)
    {
        if (count($results) === 0) {
            return $model->newCollection();
        }
        $objectIdPositions = array_flip($results);
        $filtered_results = [];
        foreach ($results as $result) {
            if (is_numeric($result)) {
                $filtered_results[] = (int) $result;
            }
        }
        $result = $model->getScoutModelsByIds($builder, $filtered_results)
            ->filter(function ($model) use ($filtered_results) {
                return in_array($model->getScoutKey(), $filtered_results);
            });
        foreach ($builder->wheres as $key => $value) {
            $result = $result->where($key, $value);
        }
        return $result->sortBy(function ($model) use ($objectIdPositions) {
            return $objectIdPositions[$model->getScoutKey()];
        });
    }
public function map ( Builder $ builder , $ results , $ model ) { if ( count ( $ results ) === 0 ) { return $ model -> newCollection ( ) ; } $ objectIdPositions = array_flip ( $ results ) ; $ filtered_results = [ ] ; foreach ( $ results as $ result ) { if ( is_numeric ( $ result ) ) { $ filtered_results [ ] = ( int ) $ result ; } } $ result = $ model -> getScoutModelsByIds ( $ builder , $ filtered_results ) -> filter ( function ( $ model ) use ( $ filtered_results ) { return in_array ( $ model -> getScoutKey ( ) , $ filtered_results ) ; } ) ; foreach ( $ builder -> wheres as $ key => $ value ) { $ result = $ result -> where ( $ key , $ value ) ; } return $ result -> sortBy ( function ( $ model ) use ( $ objectIdPositions ) { return $ objectIdPositions [ $ model -> getScoutKey ( ) ] ; } ) ; }
Map the given results to instances of the given model.
Map the given results to instances of the given model .
// sonic has no way to understand filters/wheres so we fake it on the collection