PHP code example of mtk3d / scout-sqlite-fts5

1. Go to this page and download the library: Download mtk3d/scout-sqlite-fts5 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mtk3d / scout-sqlite-fts5 example snippets


Customer::search('kowalsky')->paginate(20);

class Customer extends Model
{
    use Searchable;

    public function toSearchableArray(): array
    {
        return ['name' => $this->name, 'city' => $this->city];
    }
}

Customer::search('kowalski')->get();
Customer::search('kowalski')->where('status', 'active')->latest()->paginate(20);
Customer::search('kowalski')->take(5)->keys();

$result = Customer::search($term)->raw();

$result->pass();  // 'prefix' | 'typo' | 'any' | 'trigram' | null
$result->total(); // matches, ignoring pagination
$result->ids();   // document keys, best match first

public function searchableFilters(): array
{
    return ['tenant_id' => $this->tenant_id];
}

Customer::search('kowalski')->where('tenant_id', 1)->get();

'tokenizer' => 'unicode61 remove_diacritics 2', // add `porter` for English stemming
'passes' => ['prefix' => true, 'typo' => true, 'any' => true, 'trigram' => true],
'trigram' => ['size' => 3, 'max_grams' => 24, 'min_ratio' => 0.4],
bash
php -r 'echo (new PDO("sqlite::memory:"))->exec("CREATE VIRTUAL TABLE t USING fts5(c)") === false ? "missing" : "ok";'
bash
php artisan scout:fts5-create
php artisan scout:import "App\Models\Customer"
bash
php artisan vendor:publish --tag=scout-fts5-config