PHPackages                             enabel/typesense - 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. [Search &amp; Filtering](/categories/search)
4. /
5. enabel/typesense

ActiveLibrary[Search &amp; Filtering](/categories/search)

enabel/typesense
================

Typesense search integration with attribute-based document mapping

v1.0.2(6d ago)027↓100%MITPHPPHP &gt;=8.4

Since Mar 17Pushed 6d agoCompare

[ Source](https://github.com/Enabel/typesense-bundle)[ Packagist](https://packagist.org/packages/enabel/typesense)[ RSS](/packages/enabel-typesense/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (8)Versions (5)Used By (0)

enabel/typesense
================

[](#enabeltypesense)

A PHP library for [Typesense](https://typesense.org) with attribute-based document mapping, a fluent search API, and optional Doctrine/Symfony integrations.

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

[](#installation)

```
composer require enabel/typesense
```

Quick Start
-----------

[](#quick-start)

### 1. Define a Document

[](#1-define-a-document)

Map your PHP class to a Typesense collection using attributes:

```
use Enabel\Typesense\Mapping as Typesense;
use Enabel\Typesense\Type\StringType;

#[Typesense\Document(collection: 'products', defaultSortingField: 'popularity')]
class Product
{
    #[Typesense\Id]
    public int $id;

    #[Typesense\Field(facet: true, infix: true)]
    public string $title;

    #[Typesense\Field(sort: true)]
    public float $price;

    #[Typesense\Field]
    public bool $inStock;

    #[Typesense\Field(type: new StringType(array: true), facet: true)]
    public array $tags;

    #[Typesense\Field(sort: true, index: false)]
    public int $popularity;

    #[Typesense\Field]
    public \DateTimeImmutable $createdAt;

    #[Typesense\Field(optional: true)]
    public ?string $description;

    // Computed field — indexed but not written back on denormalization
    #[Typesense\Field]
    public function searchLabel(): string
    {
        return "{$this->title} ({$this->price})";
    }
}
```

### 2. Search

[](#2-search)

```
use Enabel\Typesense\Search\{Query, Filter, Sort};

$response = $collection->search(
    Query::create('wireless headphones')
        ->queryBy('title', 'description')
        ->filterBy(Filter::all(
            Filter::equals('inStock', true),
            Filter::between('price', 10, 500),
        ))
        ->sortBy('price', Sort::Asc)
        ->facetBy('tags')
        ->perPage(20)
);

foreach ($response->documents as $product) {
    echo "{$product->title} - \${$product->price}\n";
}

echo "Found {$response->found} results across {$response->totalPages} pages\n";
```

---

Symfony Bundle
--------------

[](#symfony-bundle)

### Installation

[](#installation-1)

```
composer require enabel/typesense symfony/framework-bundle symfony/console
```

Register the bundle (if not using Symfony Flex):

```
// config/bundles.php
return [
    // ...
    Enabel\Typesense\Bundle\EnabelTypesenseBundle::class => ['all' => true],
];
```

### Configuration

[](#configuration)

```
# config/packages/enabel_typesense.yaml
enabel_typesense:
    client:
        url: '%env(TYPESENSE_URL)%'
        api_key: '%env(TYPESENSE_API_KEY)%'

    collections:
        App\Entity\Product: ~
        App\Entity\Article: ~
```

**When `doctrine/orm` is installed**, the bundle automatically:

- Uses `DoctrineDenormalizer` as the default denormalizer (search results are fully hydrated Doctrine entities)
- Uses `DoctrineDataProvider` as the default data provider (for the `import` command)
- Registers `IndexListener` to sync entities on persist, update, and remove

No additional configuration is required for the standard Doctrine workflow.

To override the defaults globally or per collection:

```
enabel_typesense:
    client:
        url: '%env(TYPESENSE_URL)%'
        api_key: '%env(TYPESENSE_API_KEY)%'

    default_denormalizer: app.my_denormalizer     # override global default
    default_data_provider: app.my_data_provider   # override global default

    collections:
        App\Entity\Product: ~
        App\Entity\Article:
            denormalizer: app.article_denormalizer  # override per collection
            data_provider: app.article_provider
```

### Console Commands

[](#console-commands)

```
# Create all configured collections
php bin/console enabel:typesense:create

# Create a specific collection
php bin/console enabel:typesense:create --class='App\Entity\Product'

# Drop collections (requires --force)
php bin/console enabel:typesense:drop --force
php bin/console enabel:typesense:drop --class='App\Entity\Product' --force

# Import documents (batched in chunks of 100)
php bin/console enabel:typesense:import
php bin/console enabel:typesense:import --class='App\Entity\Product'

# Search a collection
php bin/console enabel:typesense:search 'App\Entity\Product' \
    --query='headphones' \
    --query-by='title,description' \
    --filter='price:queryBy('title', 'description')      // Fields to search in
    ->filterBy($filter)                    // Filter or string expression
    ->sortBy('price', Sort::Asc)           // Primary sort (resets previous sorts)
    ->thenSortBy('rating', Sort::Desc)     // Additional sort
    ->facetBy('category', 'brand')         // Facet fields
    ->maxFacetValues(20)                   // Max facet values returned
    ->page(1)                              // Page number
    ->perPage(25);                         // Results per page
```

### Filter Builder

[](#filter-builder)

```
use Enabel\Typesense\Search\Filter;

// Comparison
Filter::equals('status', 'active');
Filter::notEquals('status', 'draft');
Filter::greaterThan('price', 100);
Filter::greaterThanOrEqual('price', 100);
Filter::lessThan('price', 500);
Filter::lessThanOrEqual('price', 500);
Filter::between('price', 100, 500);

// String matching
Filter::matches('title', 'wire*');

// Set operations
Filter::in('category', ['electronics', 'computers']);
Filter::notIn('status', ['archived', 'deleted']);

// Logical operators
Filter::all($filter1, $filter2);  // AND
Filter::any($filter1, $filter2);  // OR
```

### Response Objects

[](#response-objects)

#### `Response` (standard search)

[](#response-standard-search)

PropertyTypeDescription`found``int`Total matching documents`outOf``int`Total documents in collection`page``int`Current page`searchTimeMs``int`Search duration in ms`searchCutoff``bool`Whether search was cut off`hits``Hit[]`Search hits`documents``object[]`Denormalized PHP objects (computed)`totalPages``int`Total pages (computed)`facetCounts``array`Facet results keyed by field`raw``array`Full raw Typesense response#### `Hit`

[](#hit)

PropertyTypeDescription`document``object`Denormalized PHP object`textMatch``int`Match score`raw``array`Raw hit data#### `GroupedResponse` (grouped search)

[](#groupedresponse-grouped-search)

```
$response = $collection->searchGrouped(
    Query::create('laptop')->queryBy('title'),
    groupBy: 'category',   // Field must have facet: true
    groupLimit: 5,
);

foreach ($response->groupedHits as $group) {
    echo "Group: " . implode(', ', $group->groupKey) . "\n";
    foreach ($group->hits as $hit) {
        echo "  - {$hit->document->title}\n";
    }
}
```

### Raw Search

[](#raw-search)

Bypass the query builder and response DTOs entirely:

```
$raw = $collection->searchRaw([
    'q' => '*',
    'query_by' => 'title',
    'per_page' => 10,
]);
```

---

Collection Operations
---------------------

[](#collection-operations)

```
$collection = $client->collection(Product::class);

// CRUD
$collection->upsert($product);
$collection->find('42');         // Returns Product or null
$collection->delete('42');

// Bulk import (throws ImportException on partial failure)
$collection->import([$p1, $p2, $p3]);

// Collection lifecycle
$client->create(Product::class);  // Idempotent
$client->drop(Product::class);
```

License
-------

[](#license)

MIT

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance99

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

3

Last Release

6d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/24548b753089898f260dfce842f29e7abbeaf606e95ee59b75b1b2f8818c7e4d?d=identicon)[damienlagae](/maintainers/damienlagae)

---

Top Contributors

[![gerryvdm](https://avatars.githubusercontent.com/u/626145?v=4)](https://github.com/gerryvdm "gerryvdm (14 commits)")

---

Tags

searchtypesense

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/enabel-typesense/health.svg)

```
[![Health](https://phpackages.com/badges/enabel-typesense/health.svg)](https://phpackages.com/packages/enabel-typesense)
```

###  Alternatives

[typesense/laravel-scout-typesense-driver

Laravel Scout Driver for Typesense

144616.1k3](/packages/typesense-laravel-scout-typesense-driver)[cmsig/seal

Search Engine Abstraction Layer

32185.1k35](/packages/cmsig-seal)[cmsig/seal-symfony-bundle

An integration of CMS-IG SEAL search abstraction into Symfony Framework.

15174.0k2](/packages/cmsig-seal-symfony-bundle)

PHPackages © 2026

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