定制 guestpectacular/melastic 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

guestpectacular/melastic

Composer 安装命令:

composer require guestpectacular/melastic

包简介

Meilisearch + Eloquent

README 文档

README

Melastic: Eloquent Query Builder + Meilisearch.

Melastic it's an extension that extend Laravel Scout package to implement missing Eloquent Builder capabilities using Elasticsearch with Meilisearch.

Introduction

Laravel Scout provides a simple, driver based solution for adding full-text search to your Eloquent models Using model observers. Laravel Scout only supports simple filters only using AND boolean between expressions by default, Melastic allows for more flexible queries that support AND, OR, and combined multiple scopes using nested closures.

Improvements over Laravel Scout

In this guide you will see how to configure and use Meilisearch filters in a hypothetical movie database.

Laravel Scout current state supporting only limiting to use AND operator:

// Search through users filterable attributes looking for "Pimienta", and applying filters to look where age = 38 AND where name = 'Edgar'
User::search('Pimienta')->where('age', 38)->where('name', 'Edgar')->get();

If we need to implement a custom filter using OR we need to write a raw expression using this approach:

User::search('Pimienta', function ($engine, $query, $options) {
   $options['filter'] = "age = 38 OR name = 'Edgar'";
   // ... extra filters
   return $meilisearch->search($query, $options);
})->get()

What about more custom filters?

$ids	=	[1,2,3];
User::search("Pimienta", function ($engine, $query, $options) use ($ids) {
   $options['filter'] = "(age = 38 OR name = 'Edgar') OR id NOT IN [" . implode(', ', $ids) . "]";
   return $meilisearch->search($query, $options);
})->get()

IMHO It feels kinda bloated and difficult to maintain using different dynamic filters.

Difference with Melastic

With Melastic, it is now possible to filter using natural Eloquent Builder methods, let's rewrite same example using Laravel style:

User::search('Pimienta')
->where(function ($query) {
    $query->where('age', 38)
          ->orWhere('name', 'Edgar');
})
->orWhereNotIn('id',[1,2,3])
->get();

I have ported all missing functions from Illuminate\Database\Query\Builder into Laravel\Scout\Builder. These include where, orWhere, whereIn, orWhereIn, whereNotIn, orWhereNotIn, whereExists, orWhereExists, whereNotExists, whereBetween, whereNull, orWhereNull, whereNotNull, whereIsEmpty, orWhereIsEmpty, whereIsNotEmpty, and when to use dynamic closures enabling us to practically use the same functionality as with Eloquent models.

Installation

You can install the package via composer:

composer require guestpectacular/melastic

After installing Scout, you should publish the Scout configuration file using the vendor:publish Artisan command. This command will publish the scout.php configuration file to your application's config directory:

php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"

Update your config to use Meilisearch:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Search Engine
    |--------------------------------------------------------------------------
    |
    | This option controls the default search connection that gets used while
    | using Laravel Scout. This connection is used when syncing all models
    | to the search service. You should adjust this based on your needs.
    |
    | Supported: "algolia", "meilisearch", "database", "collection", "null"
    |
    */

    'driver' => 'meilisearch',

And finally, update your models with just one line of code to use Guestpectacular\Melastic\Searchable trait to the model you would like to make searchable:

<?php
 
namespace App\Models;
 
use Illuminate\Database\Eloquent\Model;
use Guestpectacular\Melastic\Searchable;
 
class User extends Model
{
    use Searchable;
}

Changelog

Contributing

Security Vulnerabilities

Credits

License

The MIT License (MIT). Please see License File for more information.

guestpectacular/melastic 适用场景与选型建议

guestpectacular/melastic 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 122 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「Guestpectacular」 「melastic」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 guestpectacular/melastic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 guestpectacular/melastic 我们能提供哪些服务?
定制开发 / 二次开发

基于 guestpectacular/melastic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-17