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

Using Multi Search after merging to Laravel Scout #88

Open
GeorgThomassen opened this issue Feb 27, 2024 · 2 comments
Open

Using Multi Search after merging to Laravel Scout #88

GeorgThomassen opened this issue Feb 27, 2024 · 2 comments

Comments

@GeorgThomassen
Copy link

No idea if this is the right place to ask, but;

This driver has been merged upstream to the Laravel Scout repository, however it seems the Laravel team has no intention of implementing multi search for any of the drivers, including Typesense. How would you recommend one to do federated/multi search? Use the driver from this repository or?

Thanks in advance

@samuelhautcoeur
Copy link

Also interested to know if there's any clean workaround.

@moussaclarke
Copy link

moussaclarke commented Apr 13, 2024

Also have this requirement so have been digging into the libraries a bit to see if there's a lower level undocumented workaround without falling back to this driver.

If we look at the Laravel Scout core typesense engine we can see that it proxies methods dynamically onto the underlying client:
https://github.com/laravel/scout/blob/8af517e61e88c423b9e9b466713e5f3a56e588ac/src/Engines/TypesenseEngine.php#L534

This means we can get hold of the client multisearch by doing this:
$multiSearch = app(Laravel\Scout\EngineManager::class)->engine('typesense')->getMultiSearch();

We can then call perform on this and pass in our query similarly to https://github.com/typesense/laravel-scout-typesense-driver?tab=readme-ov-file#multi-search - syntax slightly different e.g. $multiSearch->perform(['searches' => $searchRequests, $options]);

See https://github.com/typesense/typesense-php/blob/4e41737b4ee416e6b2041f81f5506bdac7c823b2/src/MultiSearch.php#L39 for the signature and how it's implemented in the client.

Bear in mind as this is lower level you won't get a lot of the magic, e.g. youll be getting a simple array back rather than a builder instance, so you won't have paginateRaw without implementing it yourself, if you're using SCOUT_PREFIX you would need to add that to your collection names manually, etc

(Edits for clarity)

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