基本的にここのURL通りにすればいい
https://readouble.com/laravel/5.3/ja/scout.html
composer require laravel/scout #config/app.php設定ファイルのproviders配列へ、ScoutServiceProviderを追加します。 Laravel\Scout\ScoutServiceProvider::class, php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider" composer require algolia/algoliasearch-client-php
Postgresqlのバックアップとリストア
#バックアップの例 pg_dump -U postgres -h localhost github > github.sql #リストアの例 psql -U postgres -h locahost github < github.sql
Postgresqlへログイン
#例 psql -h localhost -d github -U postgres
Postgresqlのテーブルのカラムにインデックスを貼るには
#例 CREATE INDEX repositories_colum_name_index ON repositories USING GIN (colum_name)
Repository.phpの例
namespace App; use Laravel\Scout\Searchable; use Illuminate\Database\Eloquent\Model; class Repository extends Model { use Searchable; public function toSearchableArray() { return [ 'name' => $this->name, 'description' => $this->description, 'readme' => $this->readme, ]; } }
scout.phpの例
'driver' => env('SCOUT_DRIVER', 'pgsql'), 'pgsql' => [ // Connection to use. See config/database.php 'connection' => env('DB_CONNECTION', 'pgsql'), // You may want to update index documents directly in PostgreSQL (i.e. via triggers). // In this case you can set this value to false. 'maintain_index' => true, ],
composer require pmatseykanets/laravel-scout-postgres sudo php artisan scout:import "App\Repository"
インデックスの意味とメリット・デメリット
インデックスを作成しておくと便利ではありますがメリットだけではありません。テーブルとは別にデータを独自に保持しますので、テーブルにデータを追加するとインデックスの方にもデータが追加されます。多くのインデックスを作成した場合、データを追加するたびにテーブルに加えて全てのインデックスにデータが追加されるためデータ追加時の処理が遅くなります。
GiSTおよびGINインデックス種類
GINインデックスの検索はGiSTの約3倍高速です
GINインデックスの構築はGiSTの約3倍時間がかかります
GINインデックスに対する更新はGiSTよりも非常に低速ですが、もし高速更新サポートを無効にしている場合は10倍の低速になります(詳細は項52.3.1を見てください)
GINインデックスは、GiSTインデックスより2から3倍大きいです
参考サイト
https://github.com/pmatseykanets/laravel-scout-postgres
https://readouble.com/laravel/5.3/ja/scout.html
https://www.postgresql.jp/document/8.4/html/textsearch-indexes.html