Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sergeynilov opened this issue Jan 10, 2024 · 1 comment

Comments

@sergeynilov
Copy link

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
Copy link

Eyad-Bereh commented Jan 14, 2024

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.

  • Since you're using algolia/scout-extended package, you can just run the command php artisan scout:optimize to generate separate configuration files inside the config directory for each model that uses the Laravel\Scout\Searchable trait. Open the corresponding configuration file and look for the key advancedSyntax. By default it's set to false, set it to true and run the command php artisan scout:sync, and if you're prompted to sync the settings file to the remote answer yes.
  • If you want to do it from the dashboard, open up the index page and switch to the Configuration tab, then scroll down to the Advanced syntax link and change the switch from the right panel then save the settings.

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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants