Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Laravel full text search with scout tnt search driver

License

NotificationsYou must be signed in to change notification settings

Nazmul7989/laravel-scout-tnt-search

Repository files navigation

Install Scout

composer require laravel/scout

If you face any php extension related error during installing scout, Add this line after the installation command

composer require laravel/scout --ignore-platform-reqs

Publish config/scout.php file

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

Install TntSearch

composer require teamtnt/laravel-scout-tntsearch-driver

If you face any php extension related error during installing scout tntsearch driver, Add this line after the installation command

composer require teamtnt/laravel-scout-tntsearch-driver --ignore-platform-reqs

Add the service provider:

TeamTNT\Scout\TNTSearchScoutServiceProvider::class, Laravel\Scout\ScoutServiceProvider::class,

Then, update the default value of your config config/scout.php file to tntsearch (or update SCOUT_DRIVER in your .env):

'driver' => env('SCOUT_DRIVER', 'tntsearch'),

Finally, because tntsearch is not natively supported by Laravel, the configuration parameters is not present by default, so let's add them manually at the end of the config/scout.php file :

/*|--------------------------------------------------------------------------| MeiliSearch Configuration|--------------------------------------------------------------------------|| Here you may configure your TntSearch settings. TntSearch search| is an open source PHP engine. No extra services are required| and all indexes are store locally in `.index` files.|| See: https://github.com/teamtnt/laravel-scout-tntsearch-driver|*/'tntsearch' => [    'storage' => storage_path(), //place where the index files will be stored    'fuzziness' => env('TNTSEARCH_FUZZINESS', true),    'fuzzy' => [        'prefix_length' => 2,        'max_expansions' => 50,        'distance' => 2,    ],    'asYouType' => false,    'searchBoolean' => env('TNTSEARCH_BOOLEAN', false),    'maxDocs' => env('TNTSEARCH_MAX_DOCS', 500),],

Indexing a model

Add Laravel\Scout\Searchable trait to your desired model

<?phpnamespace App\Models;use Illuminate\Database\Eloquent\Model;use Laravel\Scout\Searchable;class Post extends Model{    use Searchable;        public $asYouType = true;    public function toSearchableArray(): array    {        return [            'id' => $this->id, // <- Always include the primary key            'title' => $this->title,            'description' => $this->description,        ];    }}

Now update your controller like this

$posts = Post::search('laravel 10')->get();$posts = Post::search($request->input('search'))->paginate();

Scout Command

//Import product to scout driverphp artisan scout:import App\Models\Post//Remove product from scout driverphp artisan scout:flush App\Models\Post//Check scout statusphp artisan scout:status

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp