SCOUT AND 검색(searchBoolean)
2020.05.05 23:58
라라벨 SCOUT 검색 설치
<!--// 1. Install SCOUT -->
# composer require laravel/scout
# php artisan vendor:publish --provider="LaravelScoutScoutServiceProvider"
<!--// 2. Add the LaravelScoutSearchable trait to the model -->
use LaravelScoutSearchable;
class 모델명 extends Model
{
use Searchable;
public $asYouType = true;
/**
* Get the indexable data array for the model.
*
* @return array
*/
public function toSearchableArray()
{
$array = $this->toArray();
// ID, NAME등 조건 검색일 경우
$array = collect($this->toArray())->only(['id', 'name'])->toArray();
return $array;
}
public function getScoutKey()
{
return $this->id;
}
}
<!--// 3. Modify "config/scout.php" -->
'driver' => env('SCOUT_DRIVER', 'tntsearch'),
'queue' => env('SCOUT_QUEUE', true),
'tntsearch' => [
'storage' => env('TNTSEARCH_STORAGE', storage_path()), //place where the index files will be stored
'fuzziness' => env('TNTSEARCH_FUZZINESS', false),
'fuzzy' => [
'prefix_length' => 2,
'max_expansions' => 50,
'distance' => 2
],
'asYouType' => false,
'searchBoolean' => env('TNTSEARCH_BOOLEAN', false), // AND 검색일 경우 true
],
<!--// 4. Modify "php.ini" extension -->
extension=pdo_sqlite
extension=sqlite3
<!--// 5. install tntsearch -->
#composer require teamtnt/laravel-scout-tntsearch-driver
<!--// 6. Modify "config/app.php" -->
'providers' => [
// ...
LaravelScoutScoutServiceProvider::class,
TeamTNTScoutTNTSearchScoutServiceProvider::class,
],
<!--// 7. Add SCOUT_DRIVER=tntsearch to your .env file -->
SCOUT_DRIVER=tntsearch
<!--// 8. add the following line to your .gitignore file. -->
/storage/*.index
<!--// 9. Then, create index in terminal -->
#php artisan scout:import App모델명
<!--// 10. 컨트롤러에 검색 구문 추가 -->
$child = new ChildProfile;
$child = ChildProfile::search($request->search)->orderBy('id', 'asc');
$childrens = $child->paginate(16);
# composer require laravel/scout
# php artisan vendor:publish --provider="LaravelScoutScoutServiceProvider"
<!--// 2. Add the LaravelScoutSearchable trait to the model -->
use LaravelScoutSearchable;
class 모델명 extends Model
{
use Searchable;
public $asYouType = true;
/**
* Get the indexable data array for the model.
*
* @return array
*/
public function toSearchableArray()
{
$array = $this->toArray();
// ID, NAME등 조건 검색일 경우
$array = collect($this->toArray())->only(['id', 'name'])->toArray();
return $array;
}
public function getScoutKey()
{
return $this->id;
}
}
<!--// 3. Modify "config/scout.php" -->
'driver' => env('SCOUT_DRIVER', 'tntsearch'),
'queue' => env('SCOUT_QUEUE', true),
'tntsearch' => [
'storage' => env('TNTSEARCH_STORAGE', storage_path()), //place where the index files will be stored
'fuzziness' => env('TNTSEARCH_FUZZINESS', false),
'fuzzy' => [
'prefix_length' => 2,
'max_expansions' => 50,
'distance' => 2
],
'asYouType' => false,
'searchBoolean' => env('TNTSEARCH_BOOLEAN', false), // AND 검색일 경우 true
],
<!--// 4. Modify "php.ini" extension -->
extension=pdo_sqlite
extension=sqlite3
<!--// 5. install tntsearch -->
#composer require teamtnt/laravel-scout-tntsearch-driver
<!--// 6. Modify "config/app.php" -->
'providers' => [
// ...
LaravelScoutScoutServiceProvider::class,
TeamTNTScoutTNTSearchScoutServiceProvider::class,
],
<!--// 7. Add SCOUT_DRIVER=tntsearch to your .env file -->
SCOUT_DRIVER=tntsearch
<!--// 8. add the following line to your .gitignore file. -->
/storage/*.index
<!--// 9. Then, create index in terminal -->
#php artisan scout:import App모델명
<!--// 10. 컨트롤러에 검색 구문 추가 -->
$child = new ChildProfile;
$child = ChildProfile::search($request->search)->orderBy('id', 'asc');
$childrens = $child->paginate(16);
Comment 0
No. | Subject | Author | Date | Views |
---|---|---|---|---|
10 | REQUEST 관련 구문 정리 | Admin | 2020.10.22 | 25 |
» | SCOUT AND 검색(searchBoolean) | Admin | 2020.05.05 | 122 |
8 | 페도라 설치후 서버 기본작업 | Admin | 2020.04.21 | 192 |
7 | Model Factory - 데이터 심기(Faker) | Admin | 2020.04.19 | 110 |
6 | SCOUT 관계 검색 | Admin | 2020.04.16 | 460 |
5 | 라라벨 Model, Controller, View 실습 | Admin | 2020.04.07 | 245 |
4 | October CMS Theme 만들기 | Admin | 2020.04.04 | 289 |
3 | October CMS 설치방법 | Admin | 2020.04.03 | 76 |
2 | Laravel 에서 라우트된 페이지에서 404 에러가 출력될 경우 - Synology | Admin | 2020.03.25 | 200 |
1 | 라라벨 설치와 기본 학습 | Admin | 2020.03.13 | 52 |