diff --git a/docs/usage.md b/docs/usage.md index d74e79ec..b19ea242 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -18,6 +18,8 @@ Table of Contents * [Bulk operations with documents](#bulk) +* [Autocomplete](#autocomplete) + * [Percolate searches](percolate.md) * [Keyword helpers](queryhelpers.md) @@ -192,4 +194,23 @@ $doc = [ $response = $client->bulk($doc); ``` - \ No newline at end of file + +### Autocomplete + +For a complete reference of payload and response, see Manticore's [Autocomplete manual](https://manual.manticoresearch.com). + +The request requires `query` and `table` defined as required parameters. + +``` +$request = [ +[ + 'body' => [ + 'query' => 'hello wo', + 'table' => 'testrt', + ], +]; + +$response = $client->autocomplete($request); +``` + + diff --git a/src/Manticoresearch/Client.php b/src/Manticoresearch/Client.php index ac16a0d9..7a9c2499 100755 --- a/src/Manticoresearch/Client.php +++ b/src/Manticoresearch/Client.php @@ -344,6 +344,18 @@ public function keywords(array $params = []) { return $response->getResponse(); } + /** + * Endpoint: autocomplete + * @param array $params + * @return mixed + */ + public function autocomplete(array $params = []) { + $endpoint = new Endpoints\Autocomplete($params); + $response = $this->request($endpoint); + + return $response->getResponse(); + } + public function explainQuery(array $params = []) { $endpoint = new Endpoints\ExplainQuery(); $endpoint->setIndex($params['index']); diff --git a/src/Manticoresearch/Endpoints/Autocomplete.php b/src/Manticoresearch/Endpoints/Autocomplete.php new file mode 100644 index 00000000..36bbdf18 --- /dev/null +++ b/src/Manticoresearch/Endpoints/Autocomplete.php @@ -0,0 +1,50 @@ +body = json_encode($body, true); + } else { + $this->body = $body; + } + } + +} diff --git a/test/Manticoresearch/Endpoints/AutocompleteTest.php b/test/Manticoresearch/Endpoints/AutocompleteTest.php new file mode 100644 index 00000000..2a38e93f --- /dev/null +++ b/test/Manticoresearch/Endpoints/AutocompleteTest.php @@ -0,0 +1,22 @@ +assertEquals('/autocomplete', $replace->getPath()); + } + + public function testGetMethod() { + $replace = new \Manticoresearch\Endpoints\Autocomplete(); + $this->assertEquals('POST', $replace->getMethod()); + } +}