承接 abrbit/laravel-scout-elasticsearch 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

abrbit/laravel-scout-elasticsearch

最新稳定版本:v1.0.6

Composer 安装命令:

composer require abrbit/laravel-scout-elasticsearch

包简介

A Laravel Scout driver for Elasticsearch with developer-friendly syntax.

README 文档

README

A developer-friendly Laravel Scout driver for Elasticsearch — built for distributed, scalable, and clean search experiences.
Crafted with ❤️ by the Abrbit team.

🚀 Features

✅ Plug-and-play with Laravel Scout
✅ Uses official Elasticsearch REST API
✅ Auto-maps documents & IDs for distributed clusters
✅ Supports multi-field search (e.g., title + description)
✅ Fully configurable via config/services.php
✅ Developer-friendly syntax — clean and minimal

📦 Installation

composer require abrbit/laravel-scout-elasticsearch

Then register your search service endpoint and credentials in .env:

SEARCH_URL=https://search.services.abrbit.com
SEARCH_TOKEN=your-api-token

⚙️ Configuration

In your config/scout.php, set the driver to abrbit:

'driver' => 'abrbit',

And in config/services.php, add:

'search' => [
    'url' => env('SEARCH_URL', 'https://example.com'),
    'token' => env('SEARCH_TOKEN'),
],

🧩 Usage

You can use Laravel Scout’s native methods directly:

use App\Models\Song;

// Paginate results
$songs = Song::search('عشق')->paginate(20);

// Get paginated raw source data
$songs = Song::search('عشق')->searchSource();

1. Get Eloquent Models (get())

This is the standard Scout method. It returns an Eloquent Collection of your models, hydrated from the database based on the IDs returned from the search.

use App\Models\Song;

// Returns a Collection of Song models
$songs = Song::search('عشق')->get();

// Paginate results
$songs = Song::search('عشق')->paginate(20);

2. Get Raw Source Data (getSource())

This is the recommended method for APIs or when you don't need full Eloquent models. It returns a clean array containing only the _source data directly from Elasticsearch, avoiding any database queries and providing excellent performance.

// Returns a clean array of the data stored in Elasticsearch
$songs = Song::search('شام')->getSource();

/*
Example Output:
[
    [
        "id" => 1,
        "title" => "شام غریبان",
        "description" => "..."
    ],
    [
        "id" => 2,
        "title" => "شام مهتاب",
        "description" => "..."
    ]
]
*/

3. Get Paginated Raw Source Data (searchSource())

This method is similar to getSource(), but it supports pagination and is optimized for partial and short-term searches (e.g., 2 characters). It returns a paginated array of source data.

// Returns a paginated array of the data stored in Elasticsearch
$songs = Song::search('شام')->searchSource();

// You can also specify the page and number of items per page
$songs = Song::search('شام')->searchSource($perPage = 15, $page = 2);

/*
Example Output:
[
    'data' => [
        [
            "id" => 1,
            "title" => "شام غریبان",
            "description" => "..."
        ],
        [
            "id" => 2,
            "title" => "شام مهتاب",
            "description" => "..."
        ]
    ],
    'total' => 100,
    'per_page' => 15,
    'current_page' => 2,
]
*/

4. Get the Raw Elasticsearch Response (raw())

This method returns the entire, unprocessed JSON response from Elasticsearch. It is useful for debugging or when you need access to metadata like took, _shards, or max_score.

// Returns the complete, raw response from the search engine
$rawResponse = Song::search('شام')->raw();

Your Eloquent model only needs to implement the Searchable trait:

use Laravel\Scout\Searchable;
use Illuminate\Database\Eloquent\Model;

class Song extends Model
{
    use Searchable;

    protected $fillable = ['title', 'description'];

    public function toSearchableArray()
    {
        return [
            'id' => $this->getKey(),
            'title' => $this->title,
            'description' => $this->description,
        ];
    }
}

🔍 Example Query

Here’s what an example query looks like under the hood:

{
  "from": 0,
  "size": 20,
  "query": {
    "multi_match": {
      "fields": ["title", "description"],
      "query": "شام"
    }
  }
}

🧠 How It Works

AbrbitSearchEngine is a custom Laravel Scout engine that:

  • Sends search requests to your Elasticsearch instance.
  • Handles _id assignment automatically by Elasticsearch.
  • Supports distributed, multi-tenant indexes like tenant_songs or user_posts.
  • Maps _source data back into Eloquent models seamlessly.

Example search response:

{
  "id": "Swv5oJkBk5ZOaUeK3x_O",
  "title": "شام غریبان",
  "description": "نوحه زیبای حاج محمود کریمی",
  "score": 6.6
}

🧰 Developer Notes

  • Designed for SaaS and multi-tenant applications.
  • Compatible with any REST-compatible Elasticsearch cluster (v8+ recommended).
  • Works perfectly with Laravel Scout’s indexing pipeline.

🧑‍💻 Contributing

We welcome contributions!
Feel free to open issues or submit pull requests.

⚖️ License

Released under the MIT License.

🌐 About Abrbit

Abrbit provides modern cloud infrastructure and SaaS services —
from DNS & mail hosting to AI, storage, and classroom platforms.

💡 Visit us at abrbit.com

abrbit/laravel-scout-elasticsearch 适用场景与选型建议

abrbit/laravel-scout-elasticsearch 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 395 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 10 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 abrbit/laravel-scout-elasticsearch 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-04