### Run Sonic Instance with Docker Source: https://github.com/ppshobi/psonic/blob/master/Readme.md Use this command to start a Sonic instance locally. Ensure you have Docker installed and a sonic.cfg file configured. ```bash $ docker run -d -p 1491:1491 -v /path/to/sonic.cfg:/etc/sonic.cfg -v /path/to/sonic/data/store:/var/lib/sonic/store/ valeriansaliou/sonic:v1.1.9 ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/ppshobi/psonic/blob/master/Readme.md Navigate into the cloned Psonic directory and install project dependencies using Composer. ```bash $ cd psonic && composer install ``` -------------------------------- ### Run Unit Tests Source: https://github.com/ppshobi/psonic/blob/master/Readme.md Execute the project's unit tests using PHPUnit. This command should be run after installing dependencies. ```bash phpunit ``` -------------------------------- ### Search Indexed Data with Psonic Source: https://github.com/ppshobi/psonic/blob/master/Readme.md Utilize the Search channel to query your indexed data. This example demonstrates searching for terms within a collection and bucket. ```php $search = new Psonic\Search(new Psonic\Client('localhost', 1491, 30)); $search->connect('SecretPassword1'); var_dump($search->query('messagesCollection', 'defaultBucket', "are")); // you should be getting an array of object keys which matched the term "are" $search->disconnect(); ``` -------------------------------- ### Get Auto-Suggestions with Psonic Source: https://github.com/ppshobi/psonic/blob/master/Readme.md Use the Search channel's suggest method for auto-completion functionality. This returns terms that match the provided prefix. ```php $search = new Psonic\Search(new Psonic\Client('localhost', 1491, 30)); $search->connect('SecretPassword1'); var_dump($search->suggest('messagesCollection', 'defaultBucket', "sho")); // you should be getting an array of terms which matched the term "sho". Considering previous example and it should output "shobi" $search->disconnect(); ``` -------------------------------- ### Instantiate and Connect Psonic Control Source: https://github.com/ppshobi/psonic/blob/master/api-docs.md Instantiate the Psonic/Control class to perform control operations. Ensure you have a valid Psonic\Client instance and provide the necessary password for connection. ```php connect($password); ``` -------------------------------- ### Connect to Psonic Search Channel Source: https://github.com/ppshobi/psonic/blob/master/api-docs.md Instantiate the Psonic/Search class to perform search operations. Requires a Psonic/Client instance and connection password. ```php connect($password); ``` -------------------------------- ### Connect to Psonic Ingest Channel Source: https://github.com/ppshobi/psonic/blob/master/api-docs.md Instantiate the Psonic/Ingest class to perform indexing operations. Requires a Psonic/Client instance and connection password. ```php connect($password); ``` -------------------------------- ### Clone Psonic Project Source: https://github.com/ppshobi/psonic/blob/master/Readme.md Clone the Psonic project repository from GitHub to your local machine. ```bash $ cd ~ && git clone https://github.com/ppshobi/psonic.git ``` -------------------------------- ### Index Data with Psonic Source: https://github.com/ppshobi/psonic/blob/master/Readme.md Use the Ingest and Control channels to push data and consolidate it on the Sonic server. Ensure a running Sonic instance is accessible. ```php $ingest = new Psonic\Ingest(new Psonic\Client('localhost', 1491, 30)); $control = new Psonic\Control(new Psonic\Client('localhost', 1491, 30)); $ingest->connect('SecretPassword1'); $control->connect('SecretPassword1'); echo $ingest->push('messagesCollection', 'defaultBucket', "1234","hi Shobi how are you?")->getStatus(); // OK echo $ingest->push('messagesCollection', 'defaultBucket', "1235","hi are you fine ?")->getStatus(); //OK echo $ingest->push('messagesCollection', 'defaultBucket', "1236","Jomit? How are you?")->getStatus(); //OK echo $control->consolidate(); // saves the data to disk $ingest->disconnect(); $control->disconnect(); ``` -------------------------------- ### Control Methods Source: https://github.com/ppshobi/psonic/blob/master/api-docs.md After connecting to the control channel, you can call various methods to manage and query the Psonic server. ```APIDOC ## Control Methods ### Description These methods are available on the `Psonic/Control` instance after a successful connection. ### Methods #### `->trigger(string $command)` ##### Description Trigger a control command. #### `->consolidate()` ##### Description Saves the data to disk. This can happen automatically based on configuration when a certain number of items are pushed to the index, but can also be called manually. #### `->ping(): string` ##### Description Pings the server. Should return '_PONG_'. #### `->info()` ##### Description Get the information about the server. #### `->disconnect()` ##### Description Disconnects the control channel. ``` -------------------------------- ### Psonic Control Class Usage Source: https://github.com/ppshobi/psonic/blob/master/api-docs.md Instantiate the Psonic/Control class to perform control operations on the Psonic server. This involves creating a Psonic/Client instance and then passing it to the Psonic/Control constructor. ```APIDOC ## Instantiate Control Class ### Description To perform control operations, you need to instantiate the `Psonic/Control` class. This requires an existing `Psonic/Client` instance. ### Usage ```php connect($password); ?> ``` ``` -------------------------------- ### Push Data to Psonic Index Source: https://github.com/ppshobi/psonic/blob/master/api-docs.md Adds an item to the Psonic index. Returns a Sonic Response. Locale is optional and can be set to 'none' to disable lexing. ```php $ingest->push($collection, $bucket, $object_id, "data", [string ]); ``` -------------------------------- ### Psonic Ingest Operations Source: https://github.com/ppshobi/psonic/blob/master/api-docs.md Instantiate the Psonic/Ingest class to perform indexing operations. After connecting, you can call various ingest-related methods. ```APIDOC ## Ingest Operations ### Description Provides methods for indexing and managing data within Psonic. ### Methods - `push(string $collection, string $bucket, string $object_id, string "data", [string ])` Adds an item to the index and returns a Sonic Response. The locale is optional and should be a valid ISO 639-3 locale. If set to 'none', lexing will be disabled. - `pop(string $collection, string $bucket, string $object_id, string "data")` Removes an item from the index and returns a Sonic Response. - `count(string $collection, [string $bucket, [string $object_id]]): int` Counts the number of items in a collection, bucket, or object. - `flushc(string $collection): int` Flushes all objects from a collection. Returns an integer indicating the number of items flushed. - `flushb(string $collection, string $bucket): int` Flushes all objects from a bucket. Returns an integer indicating the number of items flushed. - `flusho(string $collection, string $bucket, string $object_id): int` Flushes the indexed text from an object. Returns an integer indicating the number of items flushed. - `ping(): string` Pings the server. Should return '_PONG_'. - `disconnect()` Disconnects the ingest channel. ``` -------------------------------- ### Psonic Search Operations Source: https://github.com/ppshobi/psonic/blob/master/api-docs.md Instantiate the Psonic/Search class to perform search operations. After connecting, you can call various search-related methods. ```APIDOC ## Search Operations ### Description Provides methods for searching data indexed by Psonic. ### Methods - `query(string $collection, string $bucket, string $terms, [int $limit], [int $offset], [string ]): array` Returns an array of matched object identifiers. The locale is optional and should be a valid ISO 639-3 locale (e.g., 'eng' for English). If set to 'none', lexing will be disabled. - `suggest(string $collection, string $bucket, string $terms, [int $limit]): array` Returns an array of strings for autosuggestions. The locale is optional and should be a valid ISO 639-3 locale. If set to 'none', lexing will be disabled. - `ping(): string` Pings the server. Should return '_PONG_'. - `disconnect()` Disconnects the search channel. ``` -------------------------------- ### Ping Psonic Search Server Source: https://github.com/ppshobi/psonic/blob/master/api-docs.md Pings the Psonic search server to check its availability. Should return '_PONG_'. ```php echo $search->ping(); ``` -------------------------------- ### Flush Bucket in Psonic Index Source: https://github.com/ppshobi/psonic/blob/master/api-docs.md Flushes all objects from a specified bucket within a collection in the Psonic index. Returns the number of items flushed. ```php $ingest->flushb($collection, $bucket); ``` -------------------------------- ### Ping Psonic Ingest Server Source: https://github.com/ppshobi/psonic/blob/master/api-docs.md Pings the Psonic ingest server to check its availability. Should return '_PONG_'. ```php $ingest->ping(); ``` -------------------------------- ### Pop Data from Psonic Index Source: https://github.com/ppshobi/psonic/blob/master/api-docs.md Removes an item from the Psonic index and returns a Sonic Response. ```php $ingest->pop($collection, $bucket, $object_id, "data"); ``` -------------------------------- ### Flush Collection in Psonic Index Source: https://github.com/ppshobi/psonic/blob/master/api-docs.md Flushes all objects from a specified collection in the Psonic index. Returns the number of items flushed. ```php $ingest->flushc($collection); ``` -------------------------------- ### Count Items in Psonic Index Source: https://github.com/ppshobi/psonic/blob/master/api-docs.md Counts the number of items in a collection, bucket, or object within the Psonic index. ```php $ingest->count($collection,[string $bucket, [string $object_id]]); ``` -------------------------------- ### Flush Object in Psonic Index Source: https://github.com/ppshobi/psonic/blob/master/api-docs.md Flushes the indexed text from a specific object within a bucket and collection in the Psonic index. Returns the number of items flushed. ```php $ingest->flusho($collection, $bucket, $object_id); ``` -------------------------------- ### Disconnect from Psonic Search Channel Source: https://github.com/ppshobi/psonic/blob/master/api-docs.md Disconnects the Psonic search channel. ```php $search->disconnect(); ``` -------------------------------- ### Disconnect from Psonic Ingest Channel Source: https://github.com/ppshobi/psonic/blob/master/api-docs.md Disconnects the Psonic ingest channel. ```php $ingest->disconnect(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.