ez-php/search
Composer 安装命令:
composer require ez-php/search
包简介
Full-text search module for ez-php — Meilisearch and Elasticsearch drivers with event-driven index synchronisation
README 文档
README
Full-text search module for ez-php. Provides a driver-based search abstraction with support for Meilisearch, Elasticsearch, and Typesense, event-driven index synchronisation via ez-php/events, and an in-memory NullDriver for testing.
Installation
composer require ez-php/search
Requirements
- PHP 8.5+
ez-php/contractsez-php/events- A running Meilisearch, Elasticsearch, or Typesense instance (or use
NullDriverfor tests)
Configuration
Add config/search.php to your application:
return [ 'driver' => getenv('SEARCH_DRIVER') ?: 'null', // null | meilisearch | elasticsearch | typesense 'meilisearch' => [ 'host' => getenv('MEILISEARCH_HOST') ?: 'http://meilisearch:7700', 'key' => getenv('MEILISEARCH_KEY') ?: '', ], 'elasticsearch' => [ 'host' => getenv('ELASTICSEARCH_HOST') ?: 'http://elasticsearch:9200', 'user' => getenv('ELASTICSEARCH_USER') ?: '', 'password' => getenv('ELASTICSEARCH_PASSWORD') ?: '', ], 'typesense' => [ 'host' => getenv('TYPESENSE_HOST') ?: 'http://typesense:8108', 'key' => getenv('TYPESENSE_KEY') ?: '', ], ];
Register the provider in provider/modules.php:
\EzPhp\Search\SearchServiceProvider::class,
Making Entities Searchable
Implement SearchableInterface and use the Searchable trait:
use EzPhp\Search\Searchable; use EzPhp\Search\SearchableInterface; class Article implements SearchableInterface { use Searchable; public function __construct( public int $id, public string $title, public string $body, ) {} public function getSearchableKey(): string|int { return $this->id; } // Optional overrides: // public function searchableAs(): string { return 'articles'; } // public function toSearchableArray(): array { return ['id' => $this->id, 'title' => $this->title]; } }
Basic Usage
use EzPhp\Search\SearchIndex; use EzPhp\Search\SearchOptions; $search = $app->make(SearchIndex::class); $search->add($article); $search->remove($article); $result = $search->search('article', 'php tutorial'); foreach ($result->hits as $hit) { echo $hit->id . ': ' . $hit->document['title'] . PHP_EOL; } $result = $search->search( 'article', 'php', (new SearchOptions())->withLimit(10)->withOffset(0)->withFilter('status = "published"'), ); $search->flush('article');
Automatic Index Synchronisation via Events
Wire SyncSearchIndex to your ORM model events in a service provider's boot():
use EzPhp\Events\Event; use EzPhp\Search\Listeners\SyncSearchIndex; use EzPhp\Search\SearchIndex; public function boot(): void { $index = $this->app->make(SearchIndex::class); Event::listen(ArticleSaved::class, new SyncSearchIndex($index)); Event::listen(ArticleDeleted::class, new SyncSearchIndex($index, remove: true)); }
ORM events must implement HasSearchableModel:
use EzPhp\Search\Listeners\HasSearchableModel; use EzPhp\Search\SearchableInterface; class ArticleSaved implements EventInterface, HasSearchableModel { public function __construct(private Article $article) {} public function getSearchableModel(): SearchableInterface { return $this->article; } }
Events
| Event | Fired when |
|---|---|
DocumentIndexed |
A document was added or replaced |
DocumentRemoved |
A document was removed |
Drivers
| Driver | Class | Notes |
|---|---|---|
null |
NullDriver |
In-memory, for testing — no external service required |
meilisearch |
MeilisearchDriver |
Meilisearch v1.x REST API |
elasticsearch |
ElasticsearchDriver |
Elasticsearch 8.x / OpenSearch REST API |
typesense |
TypesenseDriver |
Typesense REST API; auto-creates collections with wildcard schema |
Docker
cp .env.example .env
bash start.sh
docker compose exec app composer full
ez-php/search 适用场景与选型建议
ez-php/search 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「php」 「search」 「elasticsearch」 「full-text」 「meilisearch」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ez-php/search 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ez-php/search 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ez-php/search 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
A Laravel package to retrieve data from Google Search Console
Indexed Search Autocomplete - Extends the TYPO3 Core Extension Indexed_Search searchform with an autocomplete feature.
Abstraction Layer to index and search entities
Pimcore 10.x Website Indexer (powered by Zend Search Lucene)
Symfony bundle for Elasticsearch integration with round-robin load balancing
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-23