PHPackages                             glimmer/typesense-searchable - 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. glimmer/typesense-searchable

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

glimmer/typesense-searchable
============================

An easier way to use Typesense with Laravel Scout

0631PHPCI passing

Since Mar 22Pushed 1mo agoCompare

[ Source](https://github.com/glimmer-labs/typesense-searchable)[ Packagist](https://packagist.org/packages/glimmer/typesense-searchable)[ RSS](/packages/glimmer-typesense-searchable/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Typesense Searchable - Laravel Scout
====================================

[](#typesense-searchable---laravel-scout)

[![Latest Version on Packagist](https://camo.githubusercontent.com/fc4422ea851c1c959e60fe322b88b15ebb0b008d2c3171a9c9d7a624678a9de8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f676c696d6d65722f7479706573656e73652d73656172636861626c653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/glimmer/typesense-searchable)[![GitHub Tests Action Status](https://camo.githubusercontent.com/fa55785e9f296ef2b0c866d1a76bda730ff018321f86b7505b8f460b43facb9a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c61726176656c2d676c696d6d65722f7479706573656e73652d73656172636861626c652f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d5465737473267374796c653d666c61742d737175617265)](https://github.com/laravel-glimmer/typesense-searchable/actions/workflows/tests.yml?query=branch%3Amain)[![Laravel Octane Compatibility](https://camo.githubusercontent.com/70359a356da237cd29561bc5d0bb80baae775b5ff62f288ed324755382858342/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2532304f6374616e652d436f6d70617469626c652d737563636573733f7374796c653d666c6174266c6f676f3d6c61726176656c)](https://laravel.com/docs/12.x/octane#introduction)

This is a trait that enables Laravel Eloquent models to integrate with Typesense easily when using Laravel Scout, allowing it to be indexed and searched using a schema generated directly from the model’s `searchableSchema()` method.

### Features

[](#features)

- **Easier Schema Generation**: Define parameters and field types directly within the model.
- **Field Transformation and Casting**: Automatic casting of fields to Typesense supported data types based on schema definitions.
- **Automatic ID and Carbon Instances Conversion**: Automatically adds the `id` field to the schema and converts it to a string type. If the `SoftDeletes` trait is used, the `__soft_deleted` field is also added and converted. Any field that is a Carbon instance is automatically converted to timestamp.
- **Model `toSearchableArray` Method Generation**: Automatically defines the required `toSearchableArray()` method in the model, converting the model instance to a Typesense-compatible array for indexing based on the schema definition.

> **Note:** In the examples below, the `id` field is not defined because it is added automatically to the schema. The `created_at` is converted to timestamp automatically because is a Carbon instance and defined as Int32 (or Int64). The `toSearchableArray` method is generated automatically based on the schema.

> These defaults can be overridden by manually defining the `id` or `soft_deletes` fields in the schema, using the `transformTo` modifier on Carbon instance fields, or redefining the `toSearchableArray` method.

---

### Installation

[](#installation)

```
composer require glimmer/typesense-searchable
```

Usage
-----

[](#usage)

### Schema Definition in the Model

[](#schema-definition-in-the-model)

Define the schema by implementing a static `searchableSchema()` method in your model. This method should return an array, where each key is a field name and each value is a Typesense compatible field type with optional fields parameters and modifiers.

Example usage in the `User` model:

```
use Glimmer\TypesenseSearchable\TypesenseSearchable;
use Glimmer\TypesenseSearchable\Contracts\HasTypesenseSchema;

class User extends Authenticatable implements HasTypesenseSchema
{
    use TypesenseSearchable;

    public static function searchableSchema(): array
    {
        return self::schemaAutocompletion([
            'name' => 'string|searchable', // or ['string', 'searchable']
            'email' => ['string', 'searchable:true'], // or 'string|searchable:true'
            'email_verified_at' => [
                'string',
                'transformTo' => fn($verified) => $verified->timestamp
            ],
            'created_at' => 'int32',
            'symbols_to_index' => '@#',
            'default_sorting_field' => 'created_at',
        ]);
    }
}
```

> Note: The `schemaAutocompletion()` method is a wrapper that returns the same array it receives but allows the Laravel Idea plugin to make code completion for easier schema creation. It is not required to use it, but it is recommended.

### 1. Field Types

[](#1-field-types)

Field TypeDescription`auto`Typesense automatically determines the type of data`string`Text-based field`string[]`Array of text-based values`string*`Wildcard string`int32`32-bit integer`int32[]`Array of 32-bit integers`int64`64-bit integer`int64[]`Array of 64-bit integers`float`Floating point number`float[]`Array of floats`bool`Boolean (true/false)`bool[]`Array of booleans`geopoint`Geolocation point`geopoint[]`Array of geolocation points`geopolygon`Geolocation polygon`object`JSON object`object[]`Array of JSON objects`image`Image data> Note: For additional details, refer to [Typesense field types documentation](https://typesense.org/docs/28.0/api/collections.html#field-types).

### 2. Field Parameters

[](#2-field-parameters)

Each field can be further configured with the following parameters.

ParameterDescription`searchable`Adds the field to default search queries (default: `false`)`excluded`Excludes the field from `toSearchableArray` method (default: `false`)`optional`Marks the field as optional (default: `false`)`store`Stores the field in Typesense for retrieval (default: `true`)`sort`Enables sorting on the field (default: `true` for numbers, otherwise `false`)`facet`Allows the field to be used for faceting (default: `false`)`index`Indexes the field in Typesense (default: `true`)`infix`Enables infix search on the field (default: `false`)`stem`Enables stemming (root word matching) (default: `false`)> Parameters are treated as booleans, so they can be defined as:
>
> - `parameter` (which is equivalent to `parameter:true`)
> - `parameter:true`
> - `parameter:false`

> Note: Refer to [Typesense field parameters documentation](https://typesense.org/docs/28.0/api/collections.html#field-parameters)for more information.

### Field Modifiers

[](#field-modifiers)

Field modifiers allow transformations (before sending the data to Typesense) or custom handling for fields within Typesense.

ModifierDescription`name`Renames the field in Typesense.`locale`Sets the locale for the field (default is `en` that supports UTF-8).`token_separators`Characters to separate tokens during indexing, e.g., `@#`.`symbols_to_index`Symbols to retain in the index, e.g., `%&`.`transformTo`Function that receives the current field (if it exists) and returns a transformed value. Useful for custom transformations.`valueFrom`Provides a value for the field, even if it doesn't exist. Can be anything but if it is a function, receives `$this` model.Example:

```
public static function searchableSchema(): array
{
    return [
        'name' => [
            'string',
            'searchable',
            'locale' => 'ja',
            'transformTo' => fn($name) => strtoupper($name)
        ],
        'customField' => [
            'string',
            'index:false',
            'valueFrom' => 'customValue',
            'token_separators' => '@#', // or ['@', '#']
            'symbols_to_index' => ['%', '&'], // or '%&'
        ],
        'customField2' => [
            'string',
            'store:false',
            'valueFrom' => fn($model) => $model->customValue2
        ],
    ];
}
```

> Note: Refer to [Typesense schema parameters documentation](https://typesense.org/docs/28.0/api/collections.html#schema-parameters)for more information about `locale`

### Schema Parameters as Fields

[](#schema-parameters-as-fields)

The following are the schema-level parameters, which control schema-wide settings in Typesense. They can be included directly in the `searchableSchema()` as fields but will be treated as schema parameters.

ParameterDescription`token_separators`Characters to separate tokens used during indexing, e.g., `@#`.`symbols_to_index`Symbols to retain in the index, e.g., `%&`.`default_sorting_field`Field used for default sorting; Typesense requires it to be `int32` or `float`.`enable_nested_fields`Boolean to enable or disable nested fields support.**Example:**

```
public static function searchableSchema(): array
{
    return [
        'name' => 'string|searchable',
        'token_separators' => '@#', // or ['@', '#']
        'symbols_to_index' => ['%', '&'], // or '%&'
        'default_sorting_field' => 'created_at',
        'enable_nested_fields' => true,
    ];
}
```

### Configuring `config/scout.php`

[](#configuring-configscoutphp)

To integrate with Laravel Scout, configure the model's Typesense settings in the `config/scout.php` file:

```
'model-settings' => [
    User::class => [
        'collection-schema' => [
            'fields' => User::typesenseFieldsSchema(),
            ...User::typesenseExtraConfigurationsSchema(),
        ],
        'search-parameters' => [
            'query_by' => User::typesenseFieldsQueryBy(),
        ],
    ],
],
```

> `typesenseFieldsSchema()` Generates the Typesense `fields` schema array by parsing `searchableSchema()` and applying types, modifiers, and parameters.

> `typesenseExtraConfigurationsSchema()` Generates the Typesense schema parameters by parsing `searchableSchema()` and extracting schema-level parameters.

> `typesenseFieldsQueryBy()` Generates an array of searchable fields for `query_by` in Typesense, based on fields marked as `searchable`.

Or if you are not manually modifying anything else in the `collection-schema` you may just use this shorter option:

```
'model-settings' => [
    User::class => [
        'collection-schema' => User::typesenseCollectionSchema(),
        'search-parameters' => [
            'query_by' => User::typesenseFieldsQueryBy(),
        ],
    ],
],
```

> `typesenseCollectionSchema()` Returns the entire collection schema for Typesense, including schema fields `typesenseSchemaFields()` and schema extra configurations `typesenseSchemaExtraConfigurations()` combined.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance59

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/36aacd2b09c268a80381e6792dfa2bf0f217db0cafec77ee6b3c5ce32641c2db?d=identicon)[Haruki1707](/maintainers/Haruki1707)

---

Top Contributors

[![Haruki1707](https://avatars.githubusercontent.com/u/72423267?v=4)](https://github.com/Haruki1707 "Haruki1707 (22 commits)")

### Embed Badge

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

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

###  Alternatives

[ruflin/elastica

Elasticsearch Client

2.3k50.4M203](/packages/ruflin-elastica)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15224.3M65](/packages/opensearch-project-opensearch-php)[mailerlite/laravel-elasticsearch

An easy way to use the official PHP ElasticSearch client in your Laravel applications.

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[massive/search-bundle

Massive Search Bundle

721.4M13](/packages/massive-search-bundle)[shyim/opensearch-php-dsl

OpenSearch/Elasticsearch DSL library

175.9M9](/packages/shyim-opensearch-php-dsl)[outl1ne/nova-multiselect-filter

Multiselect filter for Laravel Nova.

45802.7k3](/packages/outl1ne-nova-multiselect-filter)

PHPackages © 2026

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