Skip to content

Commit 485ef5c

Browse files
authored
Merge pull request #6 from ppshobi/develop
Added documentation & Resolves issue #5
2 parents ad94676 + 8c882f9 commit 485ef5c

5 files changed

Lines changed: 41 additions & 39 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
vendor/*
22
.idea/*
33
.phpunit.result.cache
4-
coverage.xml
4+
coverage.xml
5+
.DS_Store

api-docs.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ You need to instantiate the Psonic/Search class to do the searching operations o
66

77
```php
88
<?php
9-
10-
$search = new Psonic/Search(new Psonic/Client($host, $port, $password, $timeout));
11-
echo $search->connect();
9+
$password = 'SecretPassword';
10+
$search = new Psonic/Search(new Psonic/Client($host, $port, $timeout));
11+
echo $search->connect($password);
1212
```
1313

1414
after connecting to Search channel you can call the following methods on it
1515

1616
| Methods | Description |
1717
| --------------------------------------------------------------------- | :--------------------------------------------: |
18-
| `->query(string $collection, string $bucket, string $terms): array` | Returns an array of matched object identifiers |
19-
| `->suggest(string $collection, string $bucket, string $terms): array` | Returns an array of strings of autosuggestions |
18+
| `->query(string $collection, string $bucket, string $terms, [string <locale>]): array` | Returns an array of matched object identifiers, locale is optional, which should be a valid [ISO 639-3](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) locale (eng = English), if set to `none` lexing will be disabled |
19+
| `->suggest(string $collection, string $bucket, string $terms, [string <locale>]): array` | Returns an array of strings of autosuggestions, locale is optional, which should be a valid [ISO 639-3](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) locale (eng = English), if set to `none` lexing will be disabled |
2020
| `->ping(): string` | Pings the server, should return _PONG_ |
2121
| `->disconnect()` | Disconnects the channel |
2222

@@ -26,16 +26,16 @@ You need to instantiate the Psonic/Ingest class to do the indexing operations on
2626

2727
```php
2828
<?php
29-
30-
$ingest = new Psonic/Ingest(new Psonic/Client($host, $port, $password, $timeout));
31-
echo $ingest->connect();
29+
$password = 'SecretPassword';
30+
$ingest = new Psonic/Ingest(new Psonic/Client($host, $port, $timeout));
31+
echo $ingest->connect($password);
3232
```
3333

3434
after connecting to Ingest channel you can call the following methods on it
3535

3636
| Methods | Description |
3737
| ---------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------: |
38-
| `->push(string $collection,string $bucket, string $object_id, string "data"` | Add an item to index and Returns a Sonic Response |
38+
| `->push(string $collection,string $bucket, string $object_id, string "data", [string <locale>])` | Add an item to index and Returns a Sonic Response, locale is optional, which should be a valid [ISO 639-3](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) locale (eng = English), if set to `none` lexing will be disabled |
3939
| `->pop(string $collection,string $bucket, string $object_id, string "data"` | pops an item out of index and returns a Sonic Response |
4040
| `->count(string $collection,[string $bucket, [string $object_id]]): int` | counts the number of items in collection, bucket or object |
4141
| `->flushc(string $collection):int` | Flushes the buckets from a collection, returns a integer saying the number of items flushed |
@@ -50,9 +50,9 @@ You need to instantiate the Psonic/Control class to do the control operations on
5050

5151
```php
5252
<?php
53-
54-
$control = new Psonic/Control(new Psonic/Client($host, $port, $password, $timeout));
55-
echo $control->connect();
53+
$password = 'SecretPassword';
54+
$control = new Psonic/Control(new Psonic/Client($host, $port, $timeout));
55+
echo $control->connect($password);
5656
```
5757

5858
after connecting to control channel you can call the following methods on it
@@ -62,4 +62,5 @@ after connecting to control channel you can call the following methods on it
6262
| `->trigger(string $command)` | Trigger a control command |
6363
| `->consolidate()` | **Saves the data to disk**, when a certain number of items are pushed to index, depending on the configuration it can happen automatically. But to be on the safe side you could call this command manually |
6464
| `->ping(): string` | Pings the server, should return _PONG_ |
65+
| `->info()` | Get the information about the server |
6566
| `->disconnect()` | Disconnects the channel |

src/Control.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ public function __construct(Client $client)
2424
* @return mixed|Contracts\Response|void
2525
* @throws Exceptions\ConnectionException
2626
*/
27-
public function connect()
27+
public function connect($password = 'SecretPassword')
2828
{
2929
parent::connect();
3030

31-
$response = $this->send(new StartControlChannelCommand());
31+
$response = $this->send(new StartControlChannelCommand($password = 'SecretPassword'));
3232

33-
if($bufferSize = $response->get('bufferSize')){
34-
$this->bufferSize = (int) $bufferSize;
33+
if ($bufferSize = $response->get('bufferSize')) {
34+
$this->bufferSize = (int)$bufferSize;
3535
}
3636

3737
return $response;
@@ -58,4 +58,4 @@ public function info()
5858
{
5959
return $this->send(new InfoCommand);
6060
}
61-
}
61+
}

src/Ingest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ public function __construct(Client $client)
2828
* @return mixed|Contracts\Response|void
2929
* @throws Exceptions\ConnectionException
3030
*/
31-
public function connect()
31+
public function connect($password = 'SecretPassword')
3232
{
3333
parent::connect();
3434

35-
$response = $this->send(new StartIngestChannelCommand);
35+
$response = $this->send(new StartIngestChannelCommand($password));
3636

37-
if($bufferSize = $response->get('bufferSize')){
38-
$this->bufferSize = (int) $bufferSize;
37+
if ($bufferSize = $response->get('bufferSize')) {
38+
$this->bufferSize = (int)$bufferSize;
3939
}
4040

4141
return $response;
@@ -49,17 +49,17 @@ public function connect()
4949
* @param string $locale
5050
* @return Contracts\Response
5151
*/
52-
public function push(string $collection, string $bucket, string $object, string $text, $locale=null)
52+
public function push(string $collection, string $bucket, string $object, string $text, $locale = null)
5353
{
5454

55-
$chunks = $this->splitString($collection,$bucket, $object, $text);
55+
$chunks = $this->splitString($collection, $bucket, $object, $text);
5656

57-
if($text == "" || empty($chunks)) {
57+
if ($text == "" || empty($chunks)) {
5858
throw new InvalidArgumentException("The parameter \$text is empty");
5959
}
6060
foreach ($chunks as $chunk) {
6161
$message = $this->send(new PushCommand($collection, $bucket, $object, $chunk, $locale));
62-
if($message == false || $message == "") {
62+
if ($message == false || $message == "") {
6363
throw new InvalidArgumentException();
6464
}
6565
}
@@ -75,11 +75,11 @@ public function push(string $collection, string $bucket, string $object, string
7575
*/
7676
public function pop(string $collection, string $bucket, string $object, string $text)
7777
{
78-
$chunks = $this->splitString($collection,$bucket, $object, $text);
78+
$chunks = $this->splitString($collection, $bucket, $object, $text);
7979
$count = 0;
8080
foreach ($chunks as $chunk) {
8181
$message = $this->send(new PopCommand($collection, $bucket, $object, $chunk));
82-
if($message == false || $message == "") {
82+
if ($message == false || $message == "") {
8383
throw new InvalidArgumentException();
8484
}
8585
$count += $message->get('count');
@@ -145,4 +145,4 @@ private function splitString(string $collection, string $bucket, string $key, st
145145
{
146146
return str_split($text, ($this->bufferSize - (strlen($key . $collection . $bucket) + 20)));
147147
}
148-
}
148+
}

src/Search.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ public function __construct(Client $client)
2525
* @return mixed|Contracts\Response|void
2626
* @throws Exceptions\ConnectionException
2727
*/
28-
public function connect()
28+
public function connect($password = 'SecretPassword')
2929
{
3030
parent::connect();
3131

32-
$response = $this->send(new StartSearchChannelCommand());
32+
$response = $this->send(new StartSearchChannelCommand($password));
3333

34-
if($bufferSize = $response->get('bufferSize')){
35-
$this->bufferSize = (int) $bufferSize;
34+
if ($bufferSize = $response->get('bufferSize')) {
35+
$this->bufferSize = (int)$bufferSize;
3636
}
3737

3838
return $response;
@@ -50,13 +50,13 @@ public function query($collection, $bucket, $terms, $limit = null): array
5050
{
5151
$response = $this->send(new QueryCommand($collection, $bucket, $terms, $limit));
5252

53-
if(! $response->getStatus() == 'PENDING') {
53+
if (!$response->getStatus() == 'PENDING') {
5454
throw new CommandFailedException;
5555
}
5656

5757
$results = $this->read();
5858

59-
if(! $results->getStatus() == 'EVENT') {
59+
if (!$results->getStatus() == 'EVENT') {
6060
throw new CommandFailedException;
6161
}
6262

@@ -71,20 +71,20 @@ public function query($collection, $bucket, $terms, $limit = null): array
7171
* @return array
7272
* @throws CommandFailedException
7373
*/
74-
public function suggest($collection, $bucket, $terms, $limit=null): array
74+
public function suggest($collection, $bucket, $terms, $limit = null): array
7575
{
7676
$response = $this->send(new SuggestCommand($collection, $bucket, $terms, $limit));
7777

78-
if(! $response->getStatus() == 'PENDING') {
78+
if (!$response->getStatus() == 'PENDING') {
7979
throw new CommandFailedException;
8080
}
8181

8282
$results = $this->read();
8383

84-
if(! $results->getStatus() == 'EVENT') {
84+
if (!$results->getStatus() == 'EVENT') {
8585
throw new CommandFailedException;
8686
}
8787

8888
return $results->getResults();
8989
}
90-
}
90+
}

0 commit comments

Comments
 (0)