avadim / manticore-query-builder-php
Manticore Search 查询构建器 for PHP (非官方 PHP 客户端)
v1.15.0
2024-09-13 17:34 UTC
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 查询构建器 for PHP (非官方 PHP 客户端)
使用 Laravel-like 语法在 PHP 中为 Manticore Search 实现查询构建器
特性
- 通过 PDO 使用 MySQL 多个连接(因为 Manticore 以 SQL 为先)
- 在表名中使用占位符作为前缀
- 在表达式中使用命名参数
- 清晰的 Laravel-like 语法
- 多个 INSERT 和 REPLACE
- 支持 SELECT 的 MATCH() 和多级 WHERE
- 支持分面搜索
更详细的文档可在 /docs 文件夹中找到。Manticore Search 服务器文档:https://manual.manticoresearch.com/
快速入门指南
use avadim\Manticore\QueryBuilder\Builder as ManticoreDb; // 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 $rows = ManticoreDb::table('?products')->match('galaxy')->where('price', '>', 1100)->get();
文档
更详细的文档可在 /docs 文件夹中找到。
想要支持吗?
如果你觉得这个包很有用,就在 GitHub 上给我一颗星吧 :)