SphinxClient::Status PHP Method

Status() public method

public Status ( )
    function Status()
    {
        $this->_MBPush();
        if (!($fp = $this->_Connect())) {
            $this->_MBPop();
            return false;
        }
        $req = pack("nnNN", SEARCHD_COMMAND_STATUS, VER_COMMAND_STATUS, 4, 1);
        // len=4, body=1
        if (!$this->_Send($fp, $req, 12) || !($response = $this->_GetResponse($fp, VER_COMMAND_STATUS))) {
            $this->_MBPop();
            return false;
        }
        $res = substr($response, 4);
        // just ignore length, error handling, etc
        $p = 0;
        list($rows, $cols) = array_values(unpack("N*N*", substr($response, $p, 8)));
        $p += 8;
        $res = array();
        for ($i = 0; $i < $rows; $i++) {
            for ($j = 0; $j < $cols; $j++) {
                list(, $len) = unpack("N*", substr($response, $p, 4));
                $p += 4;
                $res[$i][] = substr($response, $p, $len);
                $p += $len;
            }
        }
        $this->_MBPop();
        return $res;
    }

Usage Example

 private function get_sugg_trigrams($word, SearchEngineOptions $options)
 {
     $trigrams = $this->BuildTrigrams($word);
     $query = "\"{$trigrams}\"/1";
     $len = strlen($word);
     $this->resetSphinx();
     $this->suggestionClient->SetMatchMode(SPH_MATCH_EXTENDED2);
     $this->suggestionClient->SetRankingMode(SPH_RANK_WORDCOUNT);
     $this->suggestionClient->SetFilterRange("len", $len - 2, $len + 4);
     $this->suggestionClient->SetSortMode(SPH_SORT_EXTENDED, "@weight DESC");
     $this->suggestionClient->SetLimits(0, 10);
     $indexes = [];
     foreach ($options->getDataboxes() as $databox) {
         $indexes[] = 'suggest' . $this->CRCdatabox($databox);
     }
     $index = implode(',', $indexes);
     $res = $this->suggestionClient->Query($query, $index);
     if ($this->suggestionClient->Status() === false) {
         return [];
     }
     if (!$res || !isset($res["matches"])) {
         return [];
     }
     $words = [];
     foreach ($res["matches"] as $match) {
         $words[] = $match['attrs']['keyword'];
     }
     return $words;
 }
All Usage Examples Of SphinxClient::Status