This package is abandoned and no longer maintained. The author suggests using the typesense/laravel-scout-typesense-driver package instead.

Typesense laravel/scout engine

v4.1.4 2021-10-29 01:19 UTC

This package is auto-updated.

Last update: 2021-12-11 21:30:57 UTC


⚠️ This project has moved to the official Typesense Github org: It was adopted as the official Typesense PHP client on Dec 2021 and ongoing development will take place there.

Please upgrade to the `typesense/laravel-scout-typesense-driver` composer package to receive new updates.

The rest of this Readme file is kept as is for posterity.

Latest Version on Packagist Postcardware

Codacy Badge PHP from Packagist Total Downloads StyleCI

# Laravel Scout Typesense Engine

Typesense engine for laravel/scout .

laravel-scout-typesense-engine  socialcard

This package makes it easy to add full text search support to your models with Laravel 7.* to 8.*.



You can install the package via composer:

composer require devloopsnet/laravel-typesense

Add the service provider:

// config/app.php
'providers' => [
    // ...

Ensure you have Laravel Scout as a provider too otherwise you will get an "unresolvable dependency" error

// config/app.php
'providers' => [
    // ...

Add SCOUT_DRIVER=typesense to your .env file

Then you should publish scout.php configuration file to your config directory

php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"

In your config/scout.php add:

'typesense' => [
    'api_key'         => 'abcd',
    'nodes'           => [
        'host'     => 'localhost',
        'port'     => '8108',
        'path'     => '',
        'protocol' => 'http',
    'nearest_node'    => [
        'host'     => 'localhost',
        'port'     => '8108',
        'path'     => '',
        'protocol' => 'http',
    'connection_timeout_seconds'   => 2,
    'healthcheck_interval_seconds' => 30,    
    'num_retries'                  => 3,
    'retry_interval_seconds'       => 1,


After you have installed scout and the Typesense driver, you need to add the Searchable trait to your models that you want to make searchable. Additionaly, define the fields you want to make searchable by defining the toSearchableArray method on the model and implement TypesenseSearch:


namespace App;

use Illuminate\Database\Eloquent\Model;
use Devloops\LaravelTypesense\Interfaces\TypesenseSearch;
use Laravel\Scout\Searchable;

class Post extends Model implements TypesenseSearch
    use Searchable;

     * Get the indexable data array for the model.
     * @return array
    public function toSearchableArray()
        $array = $this->toArray();

        // Customize array...

        return $array;

    public function getCollectionSchema(): array {
      return [
        'name' => $this->searchableAs(),
        'fields' => [
            'name' => 'title',
            'type' => 'string',
            'name' => 'created_at',
            'type' => 'int32',
        'default_sorting_field' => 'created_at',

    public function typesenseQueryBy(): array {
      return [

Then, sync the data with the search service like:

php artisan scout:import App\\Post

After that you can search your models with:

$search = Post::search('Bugs Bunny');


$search = Post::search('Bugs Bunny',function (\Laravel\Scout\Builder $builder,\Typesense\Documents $documents, string $query, array $params){
    return $documents->search($params);

Then you can apply your where(s) to the builder as follows :

//This way the default operator := will be used
$search->where('created_at', now()->unix());

//Or specially for typesense engine you can add typesense operator to the where statement
$search->where('created_at', [

*Note : For geolocation search, make sure to send an empty operator as follows

$search->where('location', [

Extended/Added methods to Scout Builder

Check Typesense Search for reference.

  • Group by
$search->groupBy(['name', 'created_at'])
$search->groupBy('name', 'created_at')
  • Order
  • Location Order
$search->orderByLocation('location',48.853, 2.344, 'desc')
$search->orderByLocation('location',48.853, 2.344, 'asc')
  • Group by limit
  • Highlight start tag
  • Highlight end tag
  • Hits limit

Adding via Query

The searchable() method will chunk the results of the query and add the records to your search index.

$post = Post::find(1);

You may also add record via collection...


---- OR

$posts = Post::where('year', '>', '2018')->get();

You may also add records via collections...




The MIT License (MIT). Please see License File for more information.