PHPackages                             teamtnt/laravel-scout-tntsearch-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. teamtnt/laravel-scout-tntsearch-driver

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

teamtnt/laravel-scout-tntsearch-driver
======================================

Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

v16.1.0(1mo ago)1.1k2.7M↓12.4%143[1 issues](https://github.com/teamtnt/laravel-scout-tntsearch-driver/issues)20MITPHPPHP &gt;=7.1|^8CI failing

Since Aug 16Pushed 1mo ago16 watchersCompare

[ Source](https://github.com/teamtnt/laravel-scout-tntsearch-driver)[ Packagist](https://packagist.org/packages/teamtnt/laravel-scout-tntsearch-driver)[ GitHub Sponsors](https://github.com/teamtnt)[ RSS](/packages/teamtnt-laravel-scout-tntsearch-driver/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (20)Versions (75)Used By (20)

TNTSearch Driver for Laravel Scout - Laravel 5.3 - 13
=====================================================

[](#tntsearch-driver-for-laravel-scout---laravel-53---13)

[![Backers on Open Collective](https://camo.githubusercontent.com/6b50eff556493032390f444d0a525e4276ce7b79b2e3754db26dac35134efb18/68747470733a2f2f6f70656e636f6c6c6563746976652e636f6d2f6c61726176656c2d73636f75742d746e747365617263682d6472697665722f6261636b6572732f62616467652e737667)](#backers) [![Sponsors on Open Collective](https://camo.githubusercontent.com/e7b531f6ad952fc6550a9a5729651d3fe1376e99555078d8dc6c25241e5d51b4/68747470733a2f2f6f70656e636f6c6c6563746976652e636f6d2f6c61726176656c2d73636f75742d746e747365617263682d6472697665722f73706f6e736f72732f62616467652e737667)](#sponsors) [![Latest Version on Packagist](https://camo.githubusercontent.com/8986de467b88076d8b87190a2d114c2162b0d7cebe1da8771bc8cf9c45f5989c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7465616d746e742f6c61726176656c2d73636f75742d746e747365617263682d6472697665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/teamtnt/laravel-scout-tntsearch-driver)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/b83821d064a5acda15b880cd7010160728e8985daa4f3da2f05f76f18991900a/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7465616d746e742f6c61726176656c2d73636f75742d746e747365617263682d6472697665722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/teamtnt/laravel-scout-tntsearch-driver)[![Quality Score](https://camo.githubusercontent.com/e319f9243930e0ad841cda80f813bcc9f99259b7129f139c3f690f948cea44b3/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7465616d746e742f6c61726176656c2d73636f75742d746e747365617263682d6472697665722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/teamtnt/laravel-scout-tntsearch-driver)[![Total Downloads](https://camo.githubusercontent.com/4c0253b3ec619cc7dbaa20a75bac54c41d04d6b35c54f4e4be071192f461167c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7465616d746e742f6c61726176656c2d73636f75742d746e747365617263682d6472697665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/teamtnt/laravel-scout-tntsearch-driver)

This package makes it easy to add full text search support to your models with Laravel 5.3 to 13.0.

Premium products
----------------

[](#premium-products)

If you find TNT Search to be one of your valuable assets, take a look at one of our premium products

[![](https://camo.githubusercontent.com/b3ab9cdab9923bc8b58260b3cf35c63f9ae83f8bf4b72816b0bef3c330d2ac15/68747470733a2f2f692e696d6775722e636f6d2f756a61677669422e706e67)](https://analytics.tnt.studio)

Support us on Open Collective
-----------------------------

[](#support-us-on-open-collective)

- [TNTSearch](https://opencollective.com/tntsearch)

Contents
--------

[](#contents)

- [Installation](#installation)
- [Usage](#usage)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)

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

[](#installation)

You can install the package via composer:

```
composer require teamtnt/laravel-scout-tntsearch-driver
```

For Laravel 11+, add the Scout and TNTSearch service providers to `bootstrap/providers.php`:

```
return [
    App\Providers\AppServiceProvider::class,
    // ...
    Laravel\Scout\ScoutServiceProvider::class,
    TeamTNT\Scout\TNTSearchScoutServiceProvider::class,
];
```

For earlier versions of Laravel, add the service provider as follows:

```
// config/app.php
'providers' => [
    // ...
    Laravel\Scout\ScoutServiceProvider::class,
    TeamTNT\Scout\TNTSearchScoutServiceProvider::class,
],
```

Add `SCOUT_DRIVER=tntsearch` 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:

```
'tntsearch' => [
    // Directory where the TNTSearch index files (SQLite .index files)
    // are written and read from. Defaults to the app's storage path;
    // point it elsewhere if indexes should live e.g. on a separate
    // local volume. Must be a local filesystem path.
    'storage'  => storage_path(),

    // Master switch for fuzzy (typo-tolerant) matching. When a query returns
    // no exact hits (or 'no_limit' is true), terms are matched by
    // Levenshtein distance instead of an exact match
    'fuzziness' => env('TNTSEARCH_FUZZINESS', false),

    'fuzzy' => [
        // Number of leading characters of the search term that must
        // match exactly before fuzzy comparison kicks in. Higher values
        // narrow the candidate word list and speed up fuzzy lookups.
        'prefix_length' => 2,

        // Caps how many candidate terms (from the index wordlist,
        // ordered by popularity) are pulled and Levenshtein-compared
        // against the search term. Lower is faster but may miss valid
        // fuzzy matches; higher is more thorough but slower.
        'max_expansions' => 50,

        // Maximum Levenshtein (edit) distance — the number of single
        // character insertions, deletions or substitutions — allowed
        // between the search term and a candidate indexed term for it
        // to still count as a match. Lower is stricter (fewer typos
        // tolerated); higher allows looser, less precise matches.
        'distance' => 2,

        // When true, fuzzy matching runs even if the exact search
        // already found results, so fuzzy matches are always added to
        // the result set. When false, fuzzy matching only kicks in as
        // a fallback when the exact search finds nothing.
        'no_limit' => true,
    ],

    // When true, the last word of the query is treated as an
    // incomplete word being typed: instead of requiring an exact
    // match, it is matched as a prefix (term LIKE 'word%') against the
    // wordlist, picking the shortest/most popular matching term. All
    // earlier words in the query still require exact matches. Useful
    // for live/instant search inputs where the final word isn't
    // finished yet. Note this option can be used on a per model
    // basis, see read me examples below.
    'asYouType' => false,

    // When true, queries are parsed as boolean expressions instead of
    // being ranked by relevance: spaces between words mean AND, " or "
    // means OR, a leading "-" before a word means NOT/exclude, and
    // parentheses can be used to group terms. Only documents matching
    // the resulting expression are returned (no relevance ranking).
    //
    // Boolean example:
    //   "php -laravel" -> docs containing "php" but NOT "laravel"
    //   "cat or dog" -> docs containing either "cat" or "dog"
    //
    // When false (default), queries use TNTSearch's normal
    // free-text search: all words are matched and results are ranked
    // by relevance, with no special meaning for "or" or "-".
    //
    // Non-boolean example:
    //   "php -laravel" -> ranked results for the literal words "php" and "laravel"
    'searchBoolean' => env('TNTSEARCH_BOOLEAN', false),

    // Caps how many documents are fetched per matched keyword from the
    // index (ordered by hit_count, i.e. most relevant first), before
    // ranking/intersecting results. This is a per-term limit, not a
    // limit on final results: if a term matches more than maxDocs
    // documents, only the top maxDocs (by popularity) are considered,
    // which can cause AND/OR boolean searches on very common words to
    // miss legitimate matches. Lower values improve performance on
    // large indexes at the cost of search completeness.
    'maxDocs' => env('TNTSEARCH_MAX_DOCS', 500),

    // Words to exclude from the index, e.g. ['a', 'the', 'in']. The stopwords
    // option lets you exclude common words (articles, prepositions) from
    // being indexed, so a search for e.g. "inns" won't fuzzy-match documents
    // that merely contain "in". Note that stopwords are applied at indexing
    // time, so you need to reimport your models after changing them
    'stopwords' => [],
],
```

To prevent your search indexes being commited to your project repository, add the following line to your `.gitignore` file.

`/storage/*.index`

Usage
-----

[](#usage)

After you have installed scout and the TNTSearch 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:

```
