renatomaldonado/manticore-laravel-search 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

renatomaldonado/manticore-laravel-search

最新稳定版本:v1.1.3

Composer 安装命令:

composer require renatomaldonado/manticore-laravel-search

包简介

Laravel driver for Manticore Search using the official PHP client

README 文档

README

A powerful integration of Manticore Search with Laravel, offering a fluent query builder and Eloquent-style API for full-text search and filtering.

Installation

composer require renatomaldonado/laravel-manticore-search

Configuration

Publish the config file:

php artisan vendor:publish --provider="ManticoreLaravel\ManticoreServiceProvider"

Then edit config/manticore.php:

return [
    'host' => env('MANTICORE_HOST', '127.0.0.1'),
    'port' => env('MANTICORE_PORT', 9306),
    'password' => env('MANTICORE_PASSWORD', null),
    'username' => env('MANTICORE_USERNAME', null),
    'transport' => env('MANTICORE_TRANSPORT', 'http'),
    'timeout' => env('MANTICORE_TIMEOUT', 5),
    'persistent' => env('MANTICORE_PERSISTENT', false),
];

Model Setup

Extend your Eloquent model with the HasManticoreSearch trait and define the searchableAs() method:

use ManticoreLaravel\Traits\HasManticoreSearch;

class Company extends Model
{
    use HasManticoreSearch;

    public function searchableAs(): array
    {
        return ['companies_index_1', 'companies_index_2'];
    }
}

Basic Usage

Match and Filter

Company::manticore()
    ->match('technology')
    ->where('country', 'US')
    ->limit(10)
    ->get();

Operators

Company::manticore()
    ->where('employees', '>=', 50)
    ->whereBetween('revenue', [10000, 50000])
    ->get();

Pagination

Company::manticore()
    ->match('startup')
    ->paginate(15);

Aggregations (Facets)

Company::manticore()
    ->aggregate('sectors', [
        'terms' => [
            'field' => 'sector',
            'size' => 5
        ]
    ])
     ->getFacets();

Sorting

Company::manticore()
    ->orderBy('created_at', 'desc')
    ->get();

Grouping

Company::manticore()
    ->groupBy('country')
    ->get();

Having

Company::manticore()
    ->select(['country', 'COUNT(*) as total'])
    ->groupBy('country')
    ->having("COUNT(*) > 1")
    ->get();

Geo Distance

Company::manticore()
    ->whereGeoDistance('location', 40.4168, -3.7038, 10000)
    ->get();

Raw SQL

Company::manticore()
    ->rawQuery("SELECT * FROM companies_index WHERE country = 'US'")
    ->get();

Convert to SQL

Company::manticore()
    ->match('ai')
    ->where('country', 'UK')
    ->toSql();

Testing

The package includes a full PHPUnit test suite. To run it:

./vendor/bin/phpunit

Make sure your Manticore server is running and your test indexes are populated.

统计信息

  • 总下载量: 50
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-05-12