sngrl\SphinxSearch\SphinxSearch::get PHP Method

get() public method

public get ( $respect_sort_order = false )
    public function get($respect_sort_order = false)
    {
        $this->_total_count = 0;
        $result = $this->_connection->query($this->_search_string, $this->_index_name);
        // Process results.
        if ($result) {
            // Get total count of existing results.
            $this->_total_count = (int) $result['total_found'];
            // Get time taken for search.
            $this->_time = $result['time'];
            if ($result['total'] && isset($result['matches'])) {
                // Get results' id's and query the database.
                $matchids = array_keys($result['matches']);
                $idString = implode(',', $matchids);
                $config = isset($this->_config['mapping']) ? $this->_config['mapping'] : $this->_config[$this->_index_name];
                if ($config) {
                    if (isset($config['modelname'])) {
                        if ($this->_eager_loads) {
                            $result = call_user_func_array($config['modelname'] . "::whereIn", array($config['column'], $matchids))->orderByRaw(\DB::raw("FIELD(id, {$idString})"))->with($this->_eager_loads)->get();
                        } else {
                            $result = call_user_func_array($config['modelname'] . "::whereIn", array($config['column'], $matchids))->orderByRaw(\DB::raw("FIELD(id, {$idString})"))->get();
                        }
                    } else {
                        $result = \DB::table($config['table'])->whereIn($config['column'], $matchids)->orderByRaw(\DB::raw("FIELD(id, {$idString})"))->get();
                    }
                }
            } else {
                $result = array();
            }
        }
        if ($respect_sort_order) {
            if (isset($matchids)) {
                $return_val = array();
                foreach ($matchids as $matchid) {
                    $key = self::getResultKeyByID($matchid, $result);
                    if (false !== $key) {
                        $return_val[] = $result[$key];
                    }
                }
                return $return_val;
            }
        }
        // important: reset the array of eager loads prior to making next call
        $this->_eager_loads = array();
        return $result;
    }