avadim / manticore-query-builder-php
Manticore Search Query Builder for PHP (unofficial PHP client)
Package info
github.com/aVadim483/manticore-query-builder-php
pkg:composer/avadim/manticore-query-builder-php
Requires
- php: ^7.4|^8.1
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- ext-pdo: *
- psr/log: >=1.1
Requires (Dev)
- phpunit/phpunit: ^9.0
README
Manticore Search Query Builder for PHP (unofficial PHP client)
Query Builder for Manticore Search in PHP with Laravel-like syntax
Features
- MySQL multiple connections via PDO (because Manticore is SQL-first)
- Placeholders as prefix in table names
- Named parameters in expressions
- Clear Laravel-like syntax
- Multiple INSERT and REPLACE
- Support MATCH() and multi-level WHERE for SELECT
- Support faceted search
- Column types are applied in both directions: PHP values on write, PHP types on read
- PSR-3 logging of queries and EXPLAIN of full-text expressions
Manticore Search server documentation: https://manual.manticoresearch.com/
Requirements
- PHP 7.4 or above with the PDO extension
- Manticore Search reachable over its SQL interface (port 9306 by default). The HTTP/JSON API is not used.
Installation
composer require avadim/manticore-query-builder-php
Quick start guide
use avadim\Manticore\QueryBuilder\Builder as ManticoreDb; use avadim\Manticore\QueryBuilder\Schema\SchemaTable; // Define config $config = [ 'defaultConnection' => 'default', 'connections' => [ // Default connection which will be used with environment variables 'default' => [ 'host' => 'localhost', 'port' => 9306, 'username' => null, 'password' => null, 'timeout' => 5, 'prefix' => 'test_', // prefix that will replace the placeholder "?<table_name>" 'force_prefix' => false, ], ], ]; // Init query builder ManticoreDb::init($config); // Create table ManticoreDb::create('?products', function (SchemaTable $table) { $table->timestamp('created_at'); $table->string('manufacturer'); $table->text('title'); $table->json('info'); $table->float('price'); $table->multi('categories'); $table->bool('on_sale'); }); // Insert single row $singleRow = [ 'created_at' => time(), 'manufacturer' => 'Samsung', 'title' => 'Galaxy S23 Ultra', 'info' => ['color' => 'Red', 'storage' => 512], 'price' => 1199.00, 'categories' => [5, 7, 11], 'on_sale' => true, ]; $res = ManticoreDb::table('?products')->insert($singleRow); // $res->result() => <id> of the new record // Insert multiple rows $multipleRows = [ [ 'created_at' => time(), 'manufacturer' => '...', 'title' => '...', 'info' => [], // ... ], [ 'created_at' => time(), 'manufacturer' => '...', 'title' => '...', 'info' => [], // ... ], ]; $res = ManticoreDb::table('?products')->insert($multipleRows); // $res->result() => array of <id> of new records // Search: get() returns rows keyed by document id, with values cast back to PHP types // ('info' as an array, 'categories' as int[], 'on_sale' as bool) $rows = ManticoreDb::table('?products')->match('galaxy')->where('price', '>', 1100)->get();
Documentation
More detailed documentation is available in the /docs folder: configuration, searching, tables, result set, logging.
Tests
vendor/bin/phpunit --testsuite unit # SQL building and parsing, no server needed vendor/bin/phpunit # adds the integration tests
The integration tests create and drop their own tables on a live server. They are skipped,
not failed, when nothing listens on MANTICORE_HOST:MANTICORE_PORT (127.0.0.1:9306
by default).
Want to support?
If you find this package useful, just give me a star on GitHub :)