laravel scout tnt search
1.0.0
composer require laravel/scout
스카우트 설치 중에 PHP 확장자 관련 오류에 직면하면 설치 명령 후이 줄을 추가하십시오.
composer require laravel/scout --ignore-platform-reqs
php artisan vendor:publish --provider="LaravelScoutScoutServiceProvider"
composer require teamtnt/laravel-scout-tntsearch-driver
스카우트 TNTERCHER 드라이버를 설치하는 동안 PHP 확장 관련 오류에 직면 한 경우 설치 명령 후이 줄을 추가하십시오.
composer require teamtnt/laravel-scout-tntsearch-driver --ignore-platform-reqs
TeamTNTScoutTNTSearchScoutServiceProvider::class,
LaravelScoutScoutServiceProvider::class,
그런 다음 config config/scout.php 파일의 기본값을 tntsearch (또는 .env에서 scout_driver를 업데이트)로 업데이트하십시오.
'driver' => env('SCOUT_DRIVER', 'tntsearch'),
마지막으로, tntearch는 Laravel에서 기본적으로 지원되지 않기 때문에 구성 매개 변수는 기본적으로 존재하지 않으므로 config/scout.php 파일 끝에 수동으로 추가하겠습니다.
/*
|--------------------------------------------------------------------------
| 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),
],
원하는 모델에 Laravel Scout 검색 가능한 특성을 추가하십시오
<?php
namespace AppModels;
use IlluminateDatabaseEloquentModel;
use LaravelScoutSearchable;
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,
];
}
}
$posts = Post::search('laravel 10')->get();
$posts = Post::search($request->input('search'))->paginate();
//Import product to scout driver
php artisan scout:import AppModelsPost
//Remove product from scout driver
php artisan scout:flush AppModelsPost
//Check scout status
php artisan scout:status