yabhq / laravel-scout-mysql-driver

Laravel Scout MySQL Driver
MIT License
522 stars 113 forks source link

Search for all words #39

Open csb346 opened 7 years ago

csb346 commented 7 years ago

First things first... Great Package!

I'm using it to perform searches on a website that is hosted on a shared server. Impossible to install other services like elasticsearch for example. My Model has a lot of text fields and relations to other models. I tried all search modes but didn't achieve the results I need. If I search for multiple words, I need to get the results that match all those words in any of the searchable fields. Unfortunately It search for each word and return all the records that have at least on of these words.

Example: 1- Title: Table vintage Body: beautiful furniture

2- Title: modern table Body: modern design

3- Title: beautiful chair Body: vintage design

Searching for "beautiful table" it returns all the items. How to get only the first one that has both words. Is that possible with fulltext search?

Thanks for your help!

sanjayojha commented 7 years ago

I think you should pass the query terms with double quote.

Barcelonczyk commented 7 years ago

You can use mysql full text search operators as a prefix for searched words (You should use boolean mode). Search for "+beautiful +table" instead of "beautiful table". Check documentation for all operators: https://dev.mysql.com/doc/refman/5.7/en/fulltext-boolean.html