typesense/typesense-php
Official PHP client for the Typesense search API. Install via Composer with an HTTPlug-compatible HTTP client, then manage collections, documents, and searches using the Typesense server API. Includes examples and safe filter string escaping.
typesense/typesense-php package is a highly specialized client for Typesense, a fast open-source search engine. It aligns perfectly with Laravel applications requiring real-time search, autocomplete, or faceted search capabilities without relying on Elasticsearch or Algolia.HttpClient or Guzzle) and integrates with Laravel’s caching (e.g., caching search results via Cache facade).Http or third-party clients.filter_by, query_by, group_by), reducing SQL-like query syntax complexity.multiSearch type changes).php-http/curl-client). Laravel’s native Http client may need a wrapper or adapter.Typesense\Exceptions\TypesenseException) must be mapped to Laravel’s exception handler for consistent logging/alerting.Http client, Guzzle, or another HTTPlug adapter? Does the team have experience with HTTPlug?500 errors, timeouts)? The package supports custom loggers—should we integrate with Laravel’s Log facade?Http client (via HTTPlug adapter like php-http/guzzle7-adapter).bus:dispatch).composer require typesense/typesense-php php-http/curl-client
Or for Laravel’s Http client:
composer require typesense/typesense-php php-http/guzzle7-adapter
config/typesense.php) for API keys, endpoints, and retries.return [
'api_key' => env('TYPESENSE_API_KEY'),
'nodes' => [
['host' => env('TYPESENSE_HOST', 'localhost'), 'port' => env('TYPESENSE_PORT', 8108), 'protocol' => 'http'],
],
'connection_timeout_seconds' => 5,
'read_timeout_seconds' => 10,
'retries' => 3,
];
public function register()
{
$this->app->singleton(TypesenseClient::class, function ($app) {
$config = $app['config']['typesense'];
return new TypesenseClient([
'nodes' => $config['nodes'],
'api_key' => $config['api_key'],
'connection_timeout_seconds' => $config['connection_timeout_seconds'],
'read_timeout_seconds' => $config['read_timeout_seconds'],
'retries' => $config['retries'],
'http_client' => $app->make(HttpClient::class), // Laravel's Http client
]);
});
}
// Old (e.g., Scout/Elasticsearch)
$results = Search::query($query)->get();
// New (Typesense)
$client = app(TypesenseClient::class);
$searchResults = $client->collections('products')
->documents()
->search('query=' . urlencode($query))
->with ties-breaker()
->with filter_by('price > 100')
->get();
Mockery) for unit tests or a local Typesense Docker instance for integration tests.docker run -p 8108:8108 -p 8109:8109 typesense/typesense:latest
FilterBy::escapeString() to prevent injection.documents()->import()).search() calls) with the client.Log facade or a monitoring tool (e.g., Sentry).Typesense\Exceptions\TypesenseException to catch API errors.$client->setDebug(true);
$client = new TypesenseClient([
'nodes' => [
['host' => 'typesense1', 'port' => 8108],
['host' => 'typesense2', 'port' => 8108],
],
// ...
]);
How can I help you explore Laravel packages today?