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

Typesense integration malforms boolean filters into integers. #873

Closed
bredmor opened this issue Oct 18, 2024 · 3 comments
Closed

Typesense integration malforms boolean filters into integers. #873

bredmor opened this issue Oct 18, 2024 · 3 comments
Assignees

Comments

@bredmor
Copy link

bredmor commented Oct 18, 2024

Scout Version

10.11.3

Scout Driver

Typesense

Laravel Version

10.48.22

PHP Version

8.2.23

Database Driver & Version

No response

SDK Version

No response

Meilisearch CLI Version

No response

Description

While searching with a boolean filter (e.g. Model::search($query)->where('myFilter', true)->get), TypesenseEngine.php will transform the true value into 1 before passing it into the typesense-php SDK to be sent to the Typsense server. This results in a Typesense\Exceptions\RequestMalformed exception with a message of "Value of filter field myFilter must be true or false."

I believe I have narrowed the issue down to the method TypesenseEngine::filters(), specifically the calls to Collection::map() here:

protected function filters(Builder $builder): string
    {
        $whereFilter = collect($builder->wheres)
            ->map(fn ($value, $key) => $this->parseWhereFilter($value, $key))
            ->values()
            ->implode(' && ');

        $whereInFilter = collect($builder->whereIns)
            ->map(fn ($value, $key) => $this->parseWhereInFilter($value, $key))
            ->values()
            ->implode(' && ');

        return $whereFilter.(
            ($whereFilter !== '' && $whereInFilter !== '') ? ' && ' : ''
        ).$whereInFilter;
    }

Looking at the data within the Builder instance passed into this function, I see boolean values for the filter parameters. However when I look at the $value parameter passed into parseWhereFilter() I see a 1 where the Builder contained true.

Steps To Reproduce

  1. Install and configure Laravel Scout in a Laravel Project
  2. Configure a searchable model with a boolean field
  3. Sync any models necessary
  4. Attempt to perform a search on that model, filtering the boolean field to true
  5. Observe a RequestMalformed exception.
@bredmor
Copy link
Author

bredmor commented Oct 18, 2024

Thinking on this, I wonder if it might be undesired functionality for the Collection/Array map() function to do this in general, or if it's expected and understood.

If the latter, I would be happy to write a PR to fix this issue for scout.

@tharropoulos
Copy link
Contributor

I'll investigate as soon as possible and report back

@crynobone
Copy link
Member

This has been merged, thanks @tharropoulos

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

3 participants