Open sanjayojha opened 7 years ago
@sanjayojha This still helps a lot. :)
To create a custom index, use:
DB::statement('ALTER TABLE posts ADD FULLTEXT INDEX posts (title, body)');
@sanjayojha, @damiantw, I did configure the toSearchableArray()
with the specific fields I want to be searchable. Is there any reason why the package still needs to make queries to information_schema
and SHOW FIELDS
before running the search question on the model when the searchable columns are set?
I wanted to use this package so that I can use the benefit of
Laravel Scout
with MySql FULLTEXT. Instead of using raw full text query I used this package so that in future I can easily change the driver and if needed can use more efficient Search driver likeelasticsearch
,TNTSearch
oralgolia
. I found many issue while installing and implementing it. But in the end I was able to install it successfully. For someone who may need this-First,
DamianTW\MySQLScout\Providers\MySQLScoutServiceProvider::class,
did not work for me it was showing error on running command. So I changes it toYab\MySQLScout\Providers\MySQLScoutServiceProvider::class,
The commandphp artisan scout:mysql-index App\\Post
didn't work for me. I changed it tophp artisan scout:mysql-index App\Post
. May be I am using windows ?Now to allow only few selected table columns you should override
toSearchableArray()
method in your model before running above command.Make sure your column is of type
text
orvarchar
To name the index name overridesearchableAs()
method in your model before running above commandNote if you already have
FULLTEXT
defined in your table then you can match the above value insearchableAs()
andtoSearchableArray()
methods by providing exact same values.Hope this help someone. Let me know if it can be improved further or I need to make any correction