PHPackages                             vuthaihoc/scout-crdb-driver - 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. vuthaihoc/scout-crdb-driver

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

vuthaihoc/scout-crdb-driver
===========================

A Laravel Scout engine for CockroachDB with support for full-text, trigram, fuzzy, prefix and exact search strategies.

v1.0.0(1mo ago)015MITPHPPHP ^8.3CI passing

Since May 27Pushed 1mo agoCompare

[ Source](https://github.com/vuthaihoc/cockroachdb-scout-driver)[ Packagist](https://packagist.org/packages/vuthaihoc/scout-crdb-driver)[ GitHub Sponsors](https://github.com/vuthaihoc)[ RSS](/packages/vuthaihoc-scout-crdb-driver/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

vuthaihoc/scout-crdb-driver
===========================

[](#vuthaihocscout-crdb-driver)

A Laravel Scout engine for **CockroachDB** with fine-grained, per-column index strategy control via PHP Attributes.

Features
--------

[](#features)

- ✅ **Full-text search** — uses `@@ plainto_tsquery()` with CockroachDB's Inverted Full-text Index
- ✅ **Trigram substring** — uses `ILIKE '%keyword%'` with GIN Trigram Index
- ✅ **Fuzzy matching** — uses `word_similarity() >= threshold` for typo-tolerant search
- ✅ **Prefix search** — uses `ILIKE 'keyword%'` with B-Tree Index
- ✅ **Exact match** — uses `col = ?` with B-Tree / GIN Index
- ✅ **Relevance ordering** — combines `ts_rank()` and `word_similarity()` automatically
- ✅ **Engine-agnostic `searchInFields()`** macro — scope search fields without touching Controller code when switching drivers

Requirements
------------

[](#requirements)

- PHP 8.3+
- Laravel 11 / 12 / 13
- Laravel Scout ≥ 10
- CockroachDB with `pg_trgm` extension (for Trigram &amp; Fuzzy features)

Installation
------------

[](#installation)

```
composer require vuthaihoc/scout-crdb-driver
```

Publish the config (optional):

```
php artisan vendor:publish --tag=scout-crdb-config
```

Set the Scout driver in `.env`:

```
SCOUT_DRIVER=crdb
```

Database Setup
--------------

[](#database-setup)

Enable the trigram extension and create appropriate indexes in your migrations:

```
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;

return new class extends Migration {
    public function up(): void
    {
        // Enable trigram extension (run once per database)
        DB::statement('CREATE EXTENSION IF NOT EXISTS pg_trgm');

        Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->string('sku')->index();           // B-Tree for prefix/exact
            $table->string('title');
            $table->text('content');
            $table->string('status')->index();         // B-Tree for exact
            $table->timestamps();
        });

        // GIN Trigram index for ILIKE / word_similarity
        DB::statement('CREATE INDEX products_title_trgm ON products USING GIN (title gin_trgm_ops)');

        // Full-text Inverted index (simple dictionary = no stemming, good for Vietnamese)
        DB::statement("CREATE INDEX products_content_fts ON products USING GIN (to_tsvector('simple', content))");
    }
};
```

Model Configuration
-------------------

[](#model-configuration)

Use PHP Attributes on `toSearchableArray()` to declare the search strategy per column:

```
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
use Laravel\Scout\Attributes\SearchUsingFullText;
use Laravel\Scout\Attributes\SearchUsingPrefix;
use Hocvt\CrdbScout\Attributes\SearchUsingFuzzy;
use Hocvt\CrdbScout\Attributes\SearchUsingTrigram;
use Hocvt\CrdbScout\Attributes\SearchUsingExact;

class Product extends Model
{
    use Searchable;

    // Full-text search with 'simple' dictionary (no stemming, good for Vietnamese)
    #[SearchUsingFullText(['content'], ['language' => 'simple'])]

    // Fuzzy search: allows typos, threshold 0.4 (0.0 = very loose, 1.0 = exact)
    #[SearchUsingFuzzy(['title'], 0.4)]

    // Trigram substring: ILIKE '%keyword%'
    #[SearchUsingTrigram(['tags'])]

    // Prefix: ILIKE 'keyword%'  (uses B-Tree index)
    #[SearchUsingPrefix(['sku'])]

    // Exact match: col = ?
    #[SearchUsingExact(['status'])]
    public function toSearchableArray(): array
    {
        return [
            'content' => $this->content,
            'title'   => $this->title,
            'tags'    => $this->tags,
            'sku'     => $this->sku,
            'status'  => $this->status,
        ];
    }
}
```

### Search Strategy Summary

[](#search-strategy-summary)

AttributeSQL GeneratedIndex Required`SearchUsingFullText``@@ plainto_tsquery(?)`GIN Full-text Inverted Index`SearchUsingFuzzy``word_similarity(?, col) >= N`GIN Trigram (`gin_trgm_ops`)`SearchUsingTrigram``col ILIKE '%keyword%'`GIN Trigram (`gin_trgm_ops`)`SearchUsingPrefix` (Scout)`col ILIKE 'keyword%'`B-Tree`SearchUsingExact``col = ?`B-Tree / GIN*(default)*`col = ?`B-TreeUsage
-----

[](#usage)

### Basic search

[](#basic-search)

```
// Searches across all configured columns
$products = Product::search('iphone')->get();
```

### Field-scoped search (engine-agnostic)

[](#field-scoped-search-engine-agnostic)

```
// Only search in 'title' and 'tags' columns
$products = Product::search('iphone')
    ->searchInFields(['title', 'tags'])
    ->get();
```

This macro works with any engine. If you switch from CRDB to Meilisearch, your Controller code stays unchanged — the engine handles the translation.

### Combining with other Scout features

[](#combining-with-other-scout-features)

```
Product::search('wireless')
    ->searchInFields(['title', 'content'])
    ->where('status', 'active')
    ->paginate(15);
```

Configuration
-------------

[](#configuration)

```
// config/scout-crdb.php
return [
    // Default threshold for #[SearchUsingFuzzy] when not explicitly set
    'default_fuzzy_threshold' => env('SCOUT_CRDB_FUZZY_THRESHOLD', 0.3),

    // Override the DB connection used for search queries (null = app default)
    'connection' => env('SCOUT_CRDB_CONNECTION', null),
];
```

Full-text Options
-----------------

[](#full-text-options)

The `SearchUsingFullText` attribute (from Laravel Scout) supports an options array:

```
// Use 'simple' dictionary (no stemming — recommended for Vietnamese or multi-language)
#[SearchUsingFullText(['content'], ['language' => 'simple'])]

// Use phrase matching
#[SearchUsingFullText(['content'], ['language' => 'english', 'mode' => 'phrase'])]

// Use websearch syntax (AND, OR, -)
#[SearchUsingFullText(['content'], ['language' => 'english', 'mode' => 'websearch'])]
```

License
-------

[](#license)

MIT

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance88

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

59d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2509658?v=4)[Stupid Dev](/maintainers/vuthaihoc)[@vuthaihoc](https://github.com/vuthaihoc)

---

Top Contributors

[![vuthaihoc](https://avatars.githubusercontent.com/u/2509658?v=4)](https://github.com/vuthaihoc "vuthaihoc (2 commits)")

---

Tags

searchlaravelscoutfuzzycockroachdbfull-texttrigramcrdb

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/vuthaihoc-scout-crdb-driver/health.svg)

```
[![Health](https://phpackages.com/badges/vuthaihoc-scout-crdb-driver/health.svg)](https://phpackages.com/packages/vuthaihoc-scout-crdb-driver)
```

###  Alternatives

[algolia/scout-extended

Scout Extended extends Laravel Scout adding algolia-specific features

4196.7M6](/packages/algolia-scout-extended)[matchish/laravel-scout-elasticsearch

Search among multiple models with ElasticSearch and Laravel Scout

7441.7M3](/packages/matchish-laravel-scout-elasticsearch)[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

399672.8k](/packages/jeroen-g-explorer)[zing/laravel-scout-opensearch

Laravel Scout custom engine for OpenSearch

36435.7k](/packages/zing-laravel-scout-opensearch)[mozex/laravel-scout-bulk-actions

Import, flush, and queue-import all your Laravel Scout searchable models at once. Auto-discovers models, runs in bulk, tracks progress.

1439.3k](/packages/mozex-laravel-scout-bulk-actions)[jonaspauleta/scout-postgres

Native Postgres full-text search + pg\_trgm engine for Laravel Scout.

211.6k](/packages/jonaspauleta-scout-postgres)

PHPackages © 2026

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