protected function toVector(Model $model)
    {
        $fields = collect($model->toSearchableArray())
            ->map(function ($value) {
                return $value === null ? '' : $value;
            });

        $bindings = collect([]);

        // The choices of parser, dictionaries and which types of tokens to index are determined
        // by the selected text search configuration which can be set globally in config/scout.php
        // file or individually for each model in searchableOptions()
        // See https://www.postgresql.org/docs/current/static/textsearch-controls.html
        $vector = 'to_tsvector(COALESCE(?, get_current_ts_config()), ?)';

        $select = $fields->map(function ($value, $key) use ($model, $vector, $bindings) {
            $bindings->push($this->searchConfig($model) ?: null)
                ->push($value);

            // Set a field weight if it was specified in Model's searchableOptions()
            if ($label = $this->rankFieldWeightLabel($model, $key)) {
                $vector = "setweight($vector, ?)";
                $bindings->push($label);
            }

            return $vector;
        })->implode(' || ');

        return $this->database
            ->query()
            ->selectRaw("$select AS tsvector", $bindings->all())
            ->value('tsvector');
    }
protected function toVector(Model $model)
    {
        $fields = collect($model->toSearchableArray())
            ->map(function ($value) {
                return $value === null ? '' : $value;
            });

        $bindings = collect([]);

        // The choices of parser, dictionaries and which types of tokens to index are determined
        // by the selected text search configuration which can be set globally in config/scout.php
        // file or individually for each model in searchableOptions()
        // See https://www.postgresql.org/docs/current/static/textsearch-controls.html
        $vector = 'to_tsvector(COALESCE(?, get_current_ts_config()), ?)';

        $select = $fields->map(function ($value, $key) use ($model, $vector, $bindings) {
            $bindings->push($this->searchConfig($model) ?: null)
                ->push($value);

            // Set a field weight if it was specified in Model's searchableOptions()
            if ($label = $this->rankFieldWeightLabel($model, $key)) {
                $vector = "setweight($vector, ?)";
                $bindings->push($label);
            }

            return $vector;
        })->implode(' || ');

        return $this->database
            ->query()
            ->selectRaw("$select AS tsvector", $bindings->all())
            ->value('tsvector');
    }
protected function toVector ( Model $ model ) { $ fields = collect ( $ model -> toSearchableArray ( ) ) -> map ( function ( $ value ) { return $ value === null ? '' : $ value ; } ) ; $ bindings = collect ( [ ] ) ; // The choices of parser, dictionaries and which types of tokens to index are determined // by the selected text search configuration which can be set globally in config/scout.php // file or individually for each model in searchableOptions() // See https://www.postgresql.org/docs/current/static/textsearch-controls.html $ vector = 'to_tsvector(COALESCE(?, get_current_ts_config()), ?)' ; $ select = $ fields -> map ( function ( $ value , $ key ) use ( $ model , $ vector , $ bindings ) { $ bindings -> push ( $ this -> searchConfig ( $ model ) ? : null ) -> push ( $ value ) ; // Set a field weight if it was specified in Model's searchableOptions() if ( $ label = $ this -> rankFieldWeightLabel ( $ model , $ key ) ) { $ vector = "setweight($vector, ?)" ; $ bindings -> push ( $ label ) ; } return $ vector ; } ) -> implode ( ' || ' ) ; return $ this -> database -> query ( ) -> selectRaw ( "$select AS tsvector" , $ bindings -> all ( ) ) -> value ( 'tsvector' ) ; }
Get the indexed value for a given model.

@param \Illuminate\Database\Eloquent\Model $model
@return string
Get the indexed value for a given model .