laravel / scout

Laravel Scout provides a driver based solution to searching your Eloquent models.
https://laravel.com/docs/scout
MIT License
1.55k stars 331 forks source link

Typesense does not handle "whereNotIns" #876

Open alexfierro opened 1 day ago

alexfierro commented 1 day ago

Scout Version

10.11

Scout Driver

Typesense

Laravel Version

11.29

PHP Version

8.2.23

Database Driver & Version

No response

SDK Version

No response

Meilisearch CLI Version

No response

Description

When using the Typesense driver, the "whereNotIn" constraints are never handled.

Within the "filters" function in TypesenseEngine.php, we can see that it handles the $builder->wheres and $builder->whereIns, but never the $builder->whereNotIns.

It should be as simple as adding a "parseWhereNotInFilter" function that does the same thing as the existing parseWhereInFilter, but changing %s:=[%s] to %s:!=[%s].... and then calling that function in the filters function.

Steps To Reproduce

This works in Typesense. (It returns matching searches where id is 10 or 11)

Content::search('foo')->whereIn('id', [10,11])->get();


This does not work as expected. (It returns all matching searches including ones where id is 10 or 11 because whereNotIn is never evaluated.)

Content::search('foo')->whereNotIn('id', [10,11])->get();

github-actions[bot] commented 1 day ago

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

tharropoulos commented 20 hours ago

I've posted a PR for this, it should fix your problem. The Typesense driver didn't take whereNotIn into account when constructing its filter clause.