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: When using an empty query callback, causes total results to significantly change #866

Closed
Braunson opened this issue Sep 18, 2024 · 4 comments
Assignees

Comments

@Braunson
Copy link

Braunson commented Sep 18, 2024

Scout Version

10.11.2

Scout Driver

Typesense

Laravel Version

10.48.2

PHP Version

8.2.23

Database Driver & Version

No response

SDK Version

No response

Meilisearch CLI Version

No response

Description

There's another issue with v10.11.2 I've noticed in #865 but this issue does appear in both v10.11.2 and v10.11.3 (I haven't tested older versions)

$results = Names::search($this->keyword)
    ->options([
        'filter_by' => $this->buildFilterString(),
        'sort_by' => implode(',', $this->sortBy),
    ])
    ->paginate(48);

The above returns ~22k results for me locally

However once I add this empty callback query, the results drop from ~22k to 48 (the pagination number) and there's no next page/page numbers shown:

->query(function ($query) {})

Query wise, nothing has changed. My initial goal was to eager load a relation to pull one column in to the hydrated returned models but found out even just adding an empty query callback causes the total results to drop significantly

Steps To Reproduce

  1. Install Laravel Scout, Typesense
  2. Setup model with thousands of records and import with Scout
  3. Setup model relation
  4. Use query above using code to re-test
@tharropoulos
Copy link
Contributor

I'll see to this ASAP, will update once I have figured out what's going on

@Braunson
Copy link
Author

Looking deeper into things it looks like the cause is the Scout 'Builder' class specifically line 499 down in the 'getTotalCount' method. If we return '$totalCount' and remove the is null check on query callback it shows the right number of total results.

Copy link

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!

@crynobone
Copy link
Member

Seems like related PR has been merged. Feel free to report back if you still have an issue.

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

No branches or pull requests

3 participants