承接 larasup/search 相关项目开发

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

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

larasup/search

Composer 安装命令:

composer require larasup/search

包简介

Typo-tolerant fuzzy search for Eloquent models, backed by PostgreSQL pg_trgm and ranked by similarity. Optionally joins larasup/localization to search every language at once.

README 文档

README

Typo-tolerant fuzzy search for Eloquent models, ranked by similarity score, backed by PostgreSQL pg_trgm and a single GIN index per column. Designed to stay fast on millions of rows.

If your models also use larasup/localization, the same query transparently spans every translated language — one Team::query()->fuzzy('real') call finds rows whose Russian, English, German, … localised name matches the query.

Quick start

use Larasup\Search\Concerns\Searchable;

class Article extends Model
{
    use Searchable;

    protected array $searchable = ['title', 'body'];
}

Article::query()->fuzzy('postgers tutoriall')->limit(20)->get();
//      ^                          ^
//      |                          ranked by similarity DESC
//      composes with any other Eloquent scope

Each result row carries a virtual search_score attribute (0..1) so you can show match strength in the UI:

foreach ($articles as $article) {
    echo $article->title.' — '.round($article->search_score * 100).'%';
}

Indexing — required for performance

The package uses the % operator and the gin_trgm_ops opclass, both of which need a GIN index on every searchable column. Add the indexes in your own migration via the helper:

use Larasup\Search\Schema\TrigramIndex;

return new class extends Migration {
    public function up(): void
    {
        TrigramIndex::create('articles', 'title');
        TrigramIndex::create('articles', 'body');
    }

    public function down(): void
    {
        TrigramIndex::drop('articles', 'title');
        TrigramIndex::drop('articles', 'body');
    }
};

If you also enable localization search, add a single shared index on the localizations table:

TrigramIndex::create('localize_localizations', 'value');

The package's own migration enables the pg_trgm extension on the connection — so CREATE EXTENSION IF NOT EXISTS pg_trgm runs automatically the first time you migrate.

Localization integration

If your model uses larasup/localization:

use Larasup\Localization\Traits\Localizable;
use Larasup\Search\Concerns\Searchable;

class Team extends Model
{
    use Localizable, Searchable;

    const LOCALIZABLE = ['name'];           // 'name' is translated per locale
    protected array $searchable = ['name']; // and 'name' is searchable
}

A single Team::query()->fuzzy('реал')->get() then matches against:

  • teams.name (the original column, e.g. English from your import)
  • every translated value in localize_localizations for class_id = Team and key = 'name'

Columns that are in $searchable but not in LOCALIZABLE are searched only in the base column, never in the localizations table — so you can mix both kinds freely.

Configuration

Publish the config file (optional):

php artisan vendor:publish --tag=search-config
// config/search.php
return [
    'localization' => [
        'enabled' => env('SEARCH_LOCALIZATION_ENABLED', true),
        'table' => env('SEARCH_LOCALIZATION_TABLE', 'localize_localizations'),
    ],
];

The localization.table value should be the fully-qualified table name in your database — change it only if you've customised localize.table_prefix or moved the localizations table into a database schema.

Tuning the similarity threshold

pg_trgm filters out matches below pg_trgm.similarity_threshold (default 0.3). Tune it globally in postgresql.conf or per-session via:

SET pg_trgm.similarity_threshold = 0.2;  -- more lenient

A lower threshold returns more (noisier) matches, a higher one returns fewer (more confident) ones. The package does not override this setting — it relies on whatever Postgres is configured to use.

License

MIT.

larasup/search 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-11