From 35afc8e2012b2496caf27f45861e049917165ed0 Mon Sep 17 00:00:00 2001 From: Radist Date: Mon, 4 Jan 2021 12:40:29 +0300 Subject: [PATCH 1/2] add suggest helpers --- src/Helper.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/Helper.php b/src/Helper.php index 53cad6a7..1ca51037 100644 --- a/src/Helper.php +++ b/src/Helper.php @@ -209,6 +209,58 @@ public function callKeywords($text, $index, $hits = null) return $this->query('CALL KEYWORDS('.implode(', ', $this->connection->quoteArr($arr)).')'); } + /** + * CALL SUGGEST syntax + * + * @param string $text + * @param string $index + * @param array $options Associative array of additional options + * + * @return SphinxQL A SphinxQL object ready to be ->execute(); + * @throws Exception\ConnectionException + * @throws Exception\DatabaseException + */ + public function callSuggest($text, $index, $options = array()) + { + $arr = array($text, $index); + + foreach ($options as $key => &$val) { + if (is_string($key)) { + $val .= ' AS '.$key; + } + } + + $arr = array_merge($this->connection->quoteArr($arr), $options); + + return $this->query('CALL SUGGEST('.implode(', ', $arr).')'); + } + + /** + * CALL QSUGGEST syntax + * + * @param string $text + * @param string $index + * @param array $options Associative array of additional options + * + * @return SphinxQL A SphinxQL object ready to be ->execute(); + * @throws Exception\ConnectionException + * @throws Exception\DatabaseException + */ + public function callQsuggest($text, $index, $options = array()) + { + $arr = array($text, $index); + + foreach ($options as $key => &$val) { + if (is_string($key)) { + $val .= ' AS '.$key; + } + } + + $arr = array_merge($this->connection->quoteArr($arr), $options); + + return $this->query('CALL QSUGGEST('.implode(', ', $arr).')'); + } + /** * DESCRIBE syntax * From 33d542e041185a97960ce2462fe883f71e24cfbd Mon Sep 17 00:00:00 2001 From: Radist Date: Mon, 4 Jan 2021 13:11:23 +0300 Subject: [PATCH 2/2] add suggest docs --- README.md | 2 ++ docs/helper.rst | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index b91131f7..7352d7ce 100755 --- a/README.md +++ b/README.md @@ -433,6 +433,8 @@ $result = (new SphinxQL($this->conn)) * `(new Helper($conn))->setVariable($name, $value, $global = false)` * `(new Helper($conn))->callSnippets($data, $index, $query, $options = array())` * `(new Helper($conn))->callKeywords($text, $index, $hits = null)` +* `(new Helper($conn))->callSuggest($text, $index, $options = array())` +* `(new Helper($conn))->callQsuggest($text, $index, $options = array())` * `(new Helper($conn))->describe($index)` * `(new Helper($conn))->createFunction($udf_name, $returns, $soname)` * `(new Helper($conn))->dropFunction($udf_name)` diff --git a/docs/helper.rst b/docs/helper.rst index a1fc0d6f..f713c168 100644 --- a/docs/helper.rst +++ b/docs/helper.rst @@ -51,6 +51,16 @@ SphinxQL Query Builder Helper Helper::create($conn) ->callKeywords($text, $index, $hits = null); +.. code-block:: php + + Helper::create($conn) + ->callSuggest($text, $index, $options = array()); + +.. code-block:: php + + Helper::create($conn) + ->callQsuggest($text, $index, $options = array()); + .. code-block:: php Helper::create($conn)