algolia / scout-extended

Scout Extended: The Full Power of Algolia in Laravel
https://www.algolia.com/doc/framework-integration/laravel/getting-started/introduction-to-scout-extended/
MIT License
393 stars 85 forks source link

Why algolia search of phrase in laravel app found all words of the phrase? #335

Open sergeynilov opened 5 months ago

sergeynilov commented 5 months ago

Working with algolia in Laravel 10 app and using algolia/algoliasearch-client-php 3.4 and algolia/scout-extended 3.0 packages I found that search method works different I expected when I enter several space splitted words : it search for all words found in records.

I tested on algolia side and see that search works in the same way :

enter image description here

Can this issue can be configurable, say in config/scout.php or on algolia side ?

Eyad-Bereh commented 5 months ago

I've found that setting the advancedSyntax option on your index to true will make any text that's double quoted be matched exactly as you said.

You can either do this from your index configuration file or the index settings page in the dashboard.

Then try searching again for "Aut recusandae et" (notice the double quotes, they're necessary for exact matching), and you should get only results that contains this phrase.

You can also control the advancedSyntax option per search if you want by passing a custom search parameter, for example:

$tasks = App\Models\Task::search('"Aut recusandae et"')->with([
    "advancedSyntax" => true
])->get();