geekybones / typesense-bundle
Symfony bundle for Typesense: attribute mapping, zero-downtime reindexing, Doctrine sync, smart and semantic search, query parsing and query suggestions.
Package info
github.com/geekybones/typesense-bundle
Type:symfony-bundle
pkg:composer/geekybones/typesense-bundle
v0.1.0
2026-10-27 10:50 UTC
Requires
- php: >=8.2
- nyholm/psr7: ^1.8
- psr/log: ^2.0 || ^3.0
- symfony/cache-contracts: ^3.5
- symfony/console: ^7.3
- symfony/event-dispatcher: ^7.2
- symfony/finder: ^7.2
- symfony/framework-bundle: ^7.2
- symfony/http-client: ^7.2
- symfony/property-access: ^7.2
- typesense/typesense-php: ^6.0
Requires (Dev)
- doctrine/orm: ^3.3
- friendsofphp/php-cs-fixer: ^3.95
- phpunit/phpunit: ^11.0
- symfony/yaml: ^8.1
Suggests
- doctrine/doctrine-bundle: Required for live sync (doctrine.event_listener)
- doctrine/orm: Required for reindexing and live sync of entities
Provides
None
Conflicts
None
Replaces
None
README
A bundle to use Typesense in a Symfony app. It covers the basics, and adds extra features on top.
The basics
- Map Doctrine entities to collections with attributes
- Keyword search, filters, sorting and facets
- Load results as Doctrine entities
The extras
- Zero-downtime reindex. A new collection is built, then swapped in.
- Live sync. The index follows your database on every save and delete.
- Enrichers. Add data that is not on the entity: fixed text, other tables, grouped options.
- Smart search. Keyword first, then search by meaning when keywords are not enough.
- Recommendations. Items like one item, or like the best hit of a search.
- Query parsing. "wool coats with gold buttons" becomes text plus a filter.
- Query suggestions. Complete what people type from popular and seeded searches.
- Stores and tenants. Keep many stores apart in one collection (guide).
- Fast repeats. Add
use_cacheand Typesense answers repeated searches from its cache. - Multi search. Run several searches in one request.
- Assistant ready. Feed a shopping or chat assistant (guide).
- Easy to extend. Replace the router, the parser or the value source with your own class.
Quick start
1. Install
Need a Typesense server first? See the official Typesense install guide or our Installation.
composer require geekybones/typesense-bundle
// config/bundles.php return [ GeekyBones\TypesenseBundle\TypesenseBundle::class => ['all' => true], ];
# config/packages/typesense.yaml typesense: api_key: '%env(TYPESENSE_API_KEY)%' nodes: - { host: '%env(TYPESENSE_HOST)%' } # http://localhost:8108
2. Map an entity
use GeekyBones\TypesenseBundle\Attribute\TypesenseCollection; use GeekyBones\TypesenseBundle\Attribute\TypesenseField; #[TypesenseCollection(name: 'products')] #[ORM\Entity] class Product { #[ORM\Id, ORM\GeneratedValue, ORM\Column] private ?int $id = null; #[ORM\Column] #[TypesenseField(queryBy: true, weight: 3)] private string $name; #[ORM\Column] #[TypesenseField(facet: true)] private ?string $brand = null; #[ORM\Column] #[TypesenseField(sort: true)] private int $price = 0; }
3. Index and search
bin/console typesense:reindex products
use GeekyBones\TypesenseBundle\Contract\SearcherInterface; final class SearchController { public function __construct(private SearcherInterface $searcher) {} public function __invoke(string $q): array { $result = $this->searcher->smartSearch(Product::class, $q); return ['found' => $result->found, 'items' => $result->documents()]; } }
After this, saving or deleting a Product updates the index for you.
Guides
| Guide | Learn how to |
|---|---|
| Installation | Install the bundle and run Typesense |
| Configuration | Set every option in typesense.yaml |
| Mapping | Turn entities into collections |
| Indexing | Reindex, keep the index in sync |
| Enrichers | Add data that is not on the entity |
| Searching | Search, filter, sort, load entities |
| Semantic search | Find results by meaning |
| Query parsing | Turn "wool coats with gold buttons" into a filter |
| Query suggestions | Complete what people type |
| Stores and tenants | Keep many stores in one collection |
| Shopping assistant | Build a chat assistant, with Typesense conversational search or your own code |
| Testing | Test your code and the bundle |
| Troubleshooting | Fix common problems |
Commands
| Command | What it does |
|---|---|
typesense:reindex [collection] |
Rebuild the index from the database |
typesense:suggestions:setup [collection] |
Create the suggestions collection |
typesense:query:parse <collection> "<query>" |
Show what the query parser finds |
Services you can inject
| Type | Use it to |
|---|---|
SearcherInterface |
Search |
IndexerInterface |
Save or delete one entity in the index |
ReindexerInterface |
Rebuild a collection |
SchemaBuilder |
Get the schema a reindex would create |
QuerySuggesterInterface |
Complete and seed search phrases |
QueryRouterInterface |
Decide when to search by meaning |
VocabularyProviderInterface |
Read or clear the values the query parser knows |
Typesense\Client |
Use the official client for anything else |
Requirements
- PHP 8.2 or newer
- Symfony 7.3 or newer
- A Typesense server (official install guide, or see Installation)
- Doctrine ORM, for reindexing, live sync and loading entities
License
MIT. See LICENSE.
Made by GeekyBones. Source and issues: github.com/geekybones/typesense-bundle.