https://github.com/statamic-rad-pack/typesense
Typesense search driver for Statamic.
https://github.com/statamic-rad-pack/typesense
statamic-addon typesense
Last synced: 2 months ago
JSON representation
Typesense search driver for Statamic.
- Host: GitHub
- URL: https://github.com/statamic-rad-pack/typesense
- Owner: statamic-rad-pack
- License: mit
- Created: 2024-08-19T15:40:05.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-11-21T12:37:00.000Z (4 months ago)
- Last Synced: 2025-11-21T14:31:48.213Z (4 months ago)
- Topics: statamic-addon, typesense
- Language: PHP
- Homepage: https://statamic.com/addons/rad-pack/typesense
- Size: 62.5 KB
- Stars: 6
- Watchers: 5
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Statamic Typesense Driver
This addon provides a [Typesense](https://typesense.org) search driver for Statamic sites.
## Requirements
* PHP 8.2+
* Laravel 10+
* Statamic 5
* Typesense 0.2+
### Installation
```bash
composer require statamic-rad-pack/typesense
```
Add the following variables to your env file:
```txt
TYPESENSE_HOST=http://127.0.0.1
TYPESENSE_API_KEY=
```
Add the new driver to the `statamic/search.php` config file:
```php
'drivers' => [
// other drivers
'typesense' => [
'client' => [
'api_key' => env('TYPESENSE_API_KEY', 'xyz'),
'nodes' => [
[
'host' => env('TYPESENSE_HOST', 'localhost'),
'port' => env('TYPESENSE_PORT', '8108'),
'path' => env('TYPESENSE_PATH', ''),
'protocol' => env('TYPESENSE_PROTOCOL', 'http'),
],
],
'nearest_node' => [
'host' => env('TYPESENSE_HOST', 'localhost'),
'port' => env('TYPESENSE_PORT', '8108'),
'path' => env('TYPESENSE_PATH', ''),
'protocol' => env('TYPESENSE_PROTOCOL', 'http'),
],
'connection_timeout_seconds' => env('TYPESENSE_CONNECTION_TIMEOUT_SECONDS', 2),
'healthcheck_interval_seconds' => env('TYPESENSE_HEALTHCHECK_INTERVAL_SECONDS', 30),
'num_retries' => env('TYPESENSE_NUM_RETRIES', 3),
'retry_interval_seconds' => env('TYPESENSE_RETRY_INTERVAL_SECONDS', 1),
],
],
],
```
You can optionally publish the config file for this package using:
```
php artisan vendor:publish --tag=statamic-typesense-config
```
### Search Settings
Any additional settings you want to define per index can be included in the `statamic/search.php` config file. The settings will be updated when the index is created.
```php
'articles' => [
'driver' => 'typesense',
'searchables' => ['collection:articles'],
'fields' => ['id', 'title', 'url', 'type', 'content', 'locale'],
'settings' => [
'schema' => [
/*
Pass an optional schema, see the Typesense documentation for more info:
https://typesense.org/docs/26.0/api/collections.html#with-pre-defined-schema
*/
'fields' => [
[
'name' => 'company_name',
'type' => 'string',
],
[
'name' => 'num_employees',
'type' => 'int32',
'sort' => true,
],
[
'name' => 'country',
'type' => 'string',
'facet' => true,
],
],
],
/*
Pass any of the options from https://typesense.org/docs/26.0/api/search.html#search-parameters
*/
'search_options' => [
/*
eg Specify a custom sort by order, see the Typesense documentation for more info:
https://typesense.org/docs/guide/ranking-and-relevance.html#ranking-based-on-relevance-and-popularity
*/
'sort_by' => '_text_match(buckets: 10):desc,weighted_score:desc',
],
/*
Set this to true to maintain the sort score order that Typesense returns
*/
'maintain_rankings' => false,
],
],
```