laravel-scout-typesense-driver icon indicating copy to clipboard operation
laravel-scout-typesense-driver copied to clipboard

Passing "empty" values to search query results in "Parameter `q` is required"

Open justrau opened this issue 1 year ago • 0 comments

Description

When using certain values for query string, "Parameter q is required" is thrown. More exactly, any value that returns true from empty(...) does not work.

Steps to reproduce

For example, App\Models\Taxon::search("0")->get() throws an error.

Expected Behavior

Found values should be returned.

Actual Behavior

"Parameter q is required" is thrown.

Metadata

Typesense Version: 0.25.1

OS:

Culprit

https://github.com/typesense/laravel-scout-typesense-driver/blob/master/src/Engines/TypesenseEngine.php#L208 and https://github.com/typesense/laravel-scout-typesense-driver/blob/master/src/Engines/TypesenseEngine.php#L208 runs array_filter on parameters array, therefore, removing the "0" query param, and typesense request is then missing the q parameter.

Possible solution

Change array_filter to a stricter function, such as rejecting only null values.

justrau avatar Jan 04 '24 16:01 justrau