avadim/manticore-query-builder-laravel

ManticoreSearch 查询构建器,适用于您的 Laravel 应用程序

v1.0.4 2023-03-20 20:08 UTC

This package is auto-updated.

Last update: 2024-09-10 19:01:11 UTC


README

Latest Stable Version Total Downloads License PHP Version Require

ManticoreSearch 查询构建器,适用于 Laravel

在您的 Laravel 或 Lumen 应用程序中使用 ManticoreSearch 查询构建器的一种简单方法。此包允许您使用类似 Laravel 的语法构建 ManticoreSearch 查询。

composer require avadim/manticore-query-builder-laravel

安装

Laravel

包的服务提供程序将自动注册其服务提供程序。

发布配置文件

php artisan vendor:publish --provider="avadim\Manticore\Laravel\ServiceProvider"

通过 .env 文件进行替代配置方法

按照上述建议发布配置文件后,您可以将以下内容添加到应用程序的 .env 文件中(使用适当的值)以配置 ManticoreSearch

MANTICORE_HOST=localhost
MANTICORE_PORT=9306
MANTICORE_USER=
MANTICORE_PASS=
MANTICORE_TIMEOUT=5

所有可用的环境变量

Lumen

如果您使用 Lumen,请将服务提供程序和配置注册到 bootstrap/app.php

// Enable shortname of facade
$app->withFacades(true, [
    'avadim\Manticore\Laravel\Facade' => 'Facade',
]);

// Register Config Files
$app->configure('manticore');

// Register Service Providers
$app->register(avadim\Manticore\Laravel\ServiceProvider::class);

手动将配置文件复制到您的应用程序中。

如何使用

// Get list of tables via the default connection
$list = \ManticoreDb::showTables();

// Get list of tables via the specified connection
$list = \ManticoreDb::connection('test')->showTables();

\ManticoreDb::table('t')->insert($data);
\ManticoreDb::table('t')->match($match)->where($where)->get();

在 Laravel 迁移中创建 ManticoreSearch 表

use avadim\Manticore\QueryBuilder\Schema\SchemaTable;

class CreateManticoreProductsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        \ManticoreDb::create('products', function (SchemaTable $table) {
            $table->timestamp('created_at');
            $table->string('name');
            $table->text('description');
            $table->float('price');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        \ManticoreDb::table('products')->dropIfExists('users');
    }
}

日志记录

您可以使用日志实例在此包中进行日志记录。

// Enable logging for all
ManticoreDb::setLogger(\Log::getLogger());

// Enable logging for the specified connection
ManticoreDb::connection('test')->setLogger(\Log::getLogger());

// Enable logging for the next query
ManticoreDb::table('test')->match($match)->where($where)->setLogger(\Log::getLogger())->get();

有关 ManticoreSearch 查询构建器的更多信息,请参阅 文档,文档地址为 avadim/manticore-query-builder-php