Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add suggest helpers #195

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)`
Expand Down
10 changes: 10 additions & 0 deletions docs/helper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
52 changes: 52 additions & 0 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down