SphinxClient::Query PHP Method

Query() public method

and return the search results
public Query ( $query, $index = "*", $comment = "" )
    function Query($query, $index = "*", $comment = "")
    {
        assert(empty($this->_reqs));
        $this->AddQuery($query, $index, $comment);
        $results = $this->RunQueries();
        $this->_reqs = array();
        // just in case it failed too early
        if (!is_array($results)) {
            return false;
        }
        // probably network error; error message should be already filled
        $this->_error = $results[0]["error"];
        $this->_warning = $results[0]["warning"];
        if ($results[0]["status"] == SEARCHD_ERROR) {
            return false;
        } else {
            return $results[0];
        }
    }

Usage Example

 /**
  * Search in sphinx client
  *
  * @param string $query
  * @param string $index
  * @return SphinxResult|string
  * @throws \Exception
  */
 public function search($query, $index = '*')
 {
     $result = $this->_sphinx_client->Query($query, $index);
     if (!$result) {
         throw new \Exception("Sphinx client error: " . $this->_sphinx_client->GetLastError());
     } else {
         if (!empty($result['warning'])) {
             return $this->_sphinx_client->GetLastWarning();
         }
         return new SphinxResult($result);
     }
 }
All Usage Examples Of SphinxClient::Query