PHPackages                             ez-php/search - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. ez-php/search

ActiveLibrary[Framework](/categories/framework)

ez-php/search
=============

Full-text search module for ez-php — Meilisearch and Elasticsearch drivers with event-driven index synchronisation

1.11.1(1mo ago)00MITPHPPHP ^8.5CI passing

Since Mar 23Pushed 1mo agoCompare

[ Source](https://github.com/ez-php/search)[ Packagist](https://packagist.org/packages/ez-php/search)[ Docs](https://github.com/ez-php/search)[ RSS](/packages/ez-php-search/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (18)Versions (26)Used By (0)

ez-php/search
=============

[](#ez-phpsearch)

Full-text search module for [ez-php](https://github.com/ez-php/framework). Provides a driver-based search abstraction with support for Meilisearch and Elasticsearch, event-driven index synchronisation via `ez-php/events`, and an in-memory `NullDriver` for testing.

Installation
------------

[](#installation)

```
composer require ez-php/search
```

Requirements
------------

[](#requirements)

- PHP 8.5+
- `ez-php/contracts`
- `ez-php/events`
- A running Meilisearch or Elasticsearch instance (or use `NullDriver` for tests)

Configuration
-------------

[](#configuration)

Add `config/search.php` to your application:

```
return [
    'driver' => getenv('SEARCH_DRIVER') ?: 'null', // null | meilisearch | elasticsearch

    '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') ?: '',
    ],
];
```

Register the provider in `provider/modules.php`:

```
\EzPhp\Search\SearchServiceProvider::class,
```

Making Entities Searchable
--------------------------

[](#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
-----------

[](#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
------------------------------------------

[](#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
------

[](#events)

EventFired when`DocumentIndexed`A document was added or replaced`DocumentRemoved`A document was removedDrivers
-------

[](#drivers)

DriverClassNotes`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 schemaDocker
------

[](#docker)

```
cp .env.example .env
bash start.sh
docker compose exec app composer full
```

###  Health Score

42

—

FairBetter than 89% of packages

Maintenance91

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 92.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

25

Last Release

44d ago

Major Versions

0.9.3 → 1.0.02026-03-24

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/122030400?v=4)[AU9500](/maintainers/AU9500)[@AU9500](https://github.com/AU9500)

---

Top Contributors

[![AU9500](https://avatars.githubusercontent.com/u/122030400?v=4)](https://github.com/AU9500 "AU9500 (63 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (5 commits)")

---

Tags

phpsearchmeilisearchframeworkelasticsearchfull-textez-php

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ez-php-search/health.svg)

```
[![Health](https://phpackages.com/badges/ez-php-search/health.svg)](https://phpackages.com/packages/ez-php-search)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
