定制 tzart/search-engine 二次开发

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

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

tzart/search-engine

Composer 安装命令:

composer require tzart/search-engine

包简介

A JSON-tree based fuzzy search engine for Laravel with multi-domain and category filtering.

README 文档

README

🔎 Laravel Search Engine

A JSON-tree based fuzzy search engine for Laravel with:

Multi-domain support (separate indexes per domain),

Autocomplete (prefix suggestions),

Fuzzy search (handles typos like aple → apple),

Category filtering (by category IDs, not titles),

Configurable tree structure stored as JSON for super-fast lookups.

Supports dynamic model/column mapping so you can plug in any Term/Category models without code changes.

🚀 Installation

Require the package:

composer require tzart/search-engine

⚙️ Configuration

Publish the config:

php artisan vendor:publish --tag=search-config

This creates config/search.php:

return [

'models' => [
    'term'     => App\Term::class,
    'category' => App\Category::class,
],

'columns' => [
    'term_id'    => 'id',
    'term_title' => 'title',
    'term_type'  => 'type',      // optional, can be null
    'domain_id'  => 'domain_id', // set null if not used
],

'search' => [
    'fuzzy_threshold'   => 2,
    'similarity_ratio'  => 40,
    'tree_path'         => storage_path('app/search/trees'),
    'branch_distance'   => 1,
    'min_candidates'    => 25,
    'token_mode'        => 'any',   // 'any' or 'all'
    'substring_min_len' => 3,
    'substring_boost'   => 20,
    'prefix_boost'      => 30,
    'return'            => 'ids',   // default return format
],

];

📖 Usage Build the tree index

Per-domain (if domain_id column is configured):

Search::buildIndex(1); // build for domain_id = 1 Search::buildIndex(2); // build for domain_id = 2

Global (if domain_id is null in config):

Search::buildIndex(); // builds one tree_all.json

Autocomplete $suggestions = Search::autocomplete('aple', 1);

// → [12, 15, 17] (Term IDs)

Fuzzy Search $results = Search::search('product', 1, [ 'category_ids' => [10, 12], 'return' => 'nodes', // full nodes instead of just IDs 'limit' => 15 ]);

/* [ [ "id" => 123, "title" => "Product with 4 Prems", "type" => "sku", "domain_id" => 1, "category_ids" => [10,12] ], ... ] */

🛠 Features

Phonetic tree branches: uses metaphone() to cluster similar words (so "aple" and "apple" share a branch).

Token + phrase indexing: splits by tokens for flexible matches ("product with 4 prems" found when searching "product").

Configurable fuzzy matching: tune similarity %, Levenshtein distance, substring/prefix boosts.

Fast JSON lookups: indexes stored as JSON in storage/app/search/trees/.

📂 JSON Tree Format

Each branch groups together similar terms:

{ "T:APPL": [ { "id": 12, "title": "Apple", "type": "fruit", "domain_id": 1, "category_ids": [2, 5] }, { "id": 15, "title": "Maple", "type": "tree", "domain_id": 1, "category_ids": [7] } ] }

📌 Roadmap

🔄 Optional Elasticsearch driver for larger datasets.

🗄 Artisan command php artisan search:rebuild for scheduled rebuilds.

🚀 Multi-language phonetic clustering.

📜 License

MIT © 2025 — tzart/search-engine

tzart/search-engine 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-23