SphinxClient::AddQuery PHP Méthode

AddQuery() public méthode

returns index into results array from RunQueries() call
public AddQuery ( $query, $index = "*", $comment = "" )
    function AddQuery($query, $index = "*", $comment = "")
    {
        // mbstring workaround
        $this->_MBPush();
        // build request
        $req = pack("NNNN", $this->_offset, $this->_limit, $this->_mode, $this->_ranker);
        if ($this->_ranker == SPH_RANK_EXPR) {
            $req .= pack("N", strlen($this->_rankexpr)) . $this->_rankexpr;
        }
        $req .= pack("N", $this->_sort);
        // (deprecated) sort mode
        $req .= pack("N", strlen($this->_sortby)) . $this->_sortby;
        $req .= pack("N", strlen($query)) . $query;
        // query itself
        $req .= pack("N", count($this->_weights));
        // weights
        foreach ($this->_weights as $weight) {
            $req .= pack("N", (int) $weight);
        }
        $req .= pack("N", strlen($index)) . $index;
        // indexes
        $req .= pack("N", 1);
        // id64 range marker
        $req .= sphPackU64($this->_min_id) . sphPackU64($this->_max_id);
        // id64 range
        // filters
        $req .= pack("N", count($this->_filters));
        foreach ($this->_filters as $filter) {
            $req .= pack("N", strlen($filter["attr"])) . $filter["attr"];
            $req .= pack("N", $filter["type"]);
            switch ($filter["type"]) {
                case SPH_FILTER_VALUES:
                    $req .= pack("N", count($filter["values"]));
                    foreach ($filter["values"] as $value) {
                        $req .= sphPackI64($value);
                    }
                    break;
                case SPH_FILTER_RANGE:
                    $req .= sphPackI64($filter["min"]) . sphPackI64($filter["max"]);
                    break;
                case SPH_FILTER_FLOATRANGE:
                    $req .= $this->_PackFloat($filter["min"]) . $this->_PackFloat($filter["max"]);
                    break;
                default:
                    assert(0 && "internal error: unhandled filter type");
            }
            $req .= pack("N", $filter["exclude"]);
        }
        // group-by clause, max-matches count, group-sort clause, cutoff count
        $req .= pack("NN", $this->_groupfunc, strlen($this->_groupby)) . $this->_groupby;
        $req .= pack("N", $this->_maxmatches);
        $req .= pack("N", strlen($this->_groupsort)) . $this->_groupsort;
        $req .= pack("NNN", $this->_cutoff, $this->_retrycount, $this->_retrydelay);
        $req .= pack("N", strlen($this->_groupdistinct)) . $this->_groupdistinct;
        // anchor point
        if (empty($this->_anchor)) {
            $req .= pack("N", 0);
        } else {
            $a =& $this->_anchor;
            $req .= pack("N", 1);
            $req .= pack("N", strlen($a["attrlat"])) . $a["attrlat"];
            $req .= pack("N", strlen($a["attrlong"])) . $a["attrlong"];
            $req .= $this->_PackFloat($a["lat"]) . $this->_PackFloat($a["long"]);
        }
        // per-index weights
        $req .= pack("N", count($this->_indexweights));
        foreach ($this->_indexweights as $idx => $weight) {
            $req .= pack("N", strlen($idx)) . $idx . pack("N", $weight);
        }
        // max query time
        $req .= pack("N", $this->_maxquerytime);
        // per-field weights
        $req .= pack("N", count($this->_fieldweights));
        foreach ($this->_fieldweights as $field => $weight) {
            $req .= pack("N", strlen($field)) . $field . pack("N", $weight);
        }
        // comment
        $req .= pack("N", strlen($comment)) . $comment;
        // attribute overrides
        $req .= pack("N", count($this->_overrides));
        foreach ($this->_overrides as $key => $entry) {
            $req .= pack("N", strlen($entry["attr"])) . $entry["attr"];
            $req .= pack("NN", $entry["type"], count($entry["values"]));
            foreach ($entry["values"] as $id => $val) {
                assert(is_numeric($id));
                assert(is_numeric($val));
                $req .= sphPackU64($id);
                switch ($entry["type"]) {
                    case SPH_ATTR_FLOAT:
                        $req .= $this->_PackFloat($val);
                        break;
                    case SPH_ATTR_BIGINT:
                        $req .= sphPackI64($val);
                        break;
                    default:
                        $req .= pack("N", $val);
                        break;
                }
            }
        }
        // select-list
        $req .= pack("N", strlen($this->_select)) . $this->_select;
        // mbstring workaround
        $this->_MBPop();
        // store request to requests array
        $this->_reqs[] = $req;
        return count($this->_reqs) - 1;
    }

Usage Example

Exemple #1
0
 /**
  * 增加批量查询
  *
  * @param string $query The query string that we are searching for.
  * @param array $indexes The indexes to perform the search on.
  */
 function addQuery($query, array $indexes)
 {
     $indexNames = '';
     foreach ($indexes as &$label) {
         if (isset($this->indexes[$label])) {
             $indexNames .= $this->indexes[$label] . ' ';
         }
     }
     if (!empty($indexNames)) {
         $this->sphinx->AddQuery($query, $indexNames);
     }
 }
All Usage Examples Of SphinxClient::AddQuery