nin / mysql-ft-search
v1.2
2021-10-17 03:32 UTC
Requires
- illuminate/database: ^6.0|^7.0|^8.0
- laravel/scout: ^9.2
Requires (Dev)
- orchestra/testbench: ^4.0|^5.0|^6.0
- phpunit/phpunit: ^8.0|^9.0
This package is auto-updated.
Last update: 2025-01-17 11:11:32 UTC
README
Laravel MySQL Fulltext search engine for the laravel scout
Usage:
Required
MySql store engine:
- MyISAM
- InnoDB: version ^5.5
To be able to search with 2 characters, configure Minimum Word Length:
-
MyISAM:
ft_min_word_len = 2
-
InnoDB:
innodb_ft_min_token_size = 2
Laravel Scout:
First, You need install Laravel Scout package.
Install:
Composer:
$ composer require nin/mysql-ft-search
If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php
Nin\MySqlFtSearc\ServiceProvider::class,
Publish config:
$ php artisan vendor:publish --provider="Nin\MySqlFtSearc\ServiceProvider"
Laravel scout driver configuration:
SCOUT_DRIVER=mysql # Refer to config('mysql-ft-search.scout_driver_name')
Schema:
Make FullText column.
use Illuminate\Database\Migrations\Migration; use Nin\MySqlFtSearch\Facade as FtSchema; class CreatePostsTable extends Migration { public function up() { FtSchema::create('posts', function (Blueprint $table) { $table->id(); $table->string('title'); $table->fulltext(['title']); }); } }
Configuring Model:
The columns of the full text index.
use Illuminate\Database\Eloquent\Model; use Laravel\Scout\Searchable; class Post extends Model { use Searchable; /** * The columns of the full text index */ public $searchable = [ 'title', ]; }
Searching:
use App\Models\Post; $rs = Post::search('Foo')->get();