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

Scout integration #32

Open
lindyhopchris opened this issue Feb 22, 2021 · 8 comments
Open

Scout integration #32

lindyhopchris opened this issue Feb 22, 2021 · 8 comments

Comments

@lindyhopchris
Copy link
Contributor

Need to work out how to integrate Scout into index queries (and to-many relationship queries). This has been requested in the previous package here:
cloudcreativity/laravel-json-api#449

And the solution should probably take into account how Nova do it (although it's a lot more complicated in our scenario because it's not just tied to an input box that searches a specific resource, it's tied to a client's index query that could contain standard filters).

Nova solution here:
https://nova.laravel.com/docs/3.0/search/scout-integration.html

@cdubz
Copy link

cdubz commented Feb 22, 2021

Thanks, @lindyhopchris. I didn't realize this package had moved.

I spent some time playing around with this yesterday but didn't get very far -- as you say it is a bit complicated. In other frameworks (or one, at least) I have seen the search index implemented as a separate endpoint for the searchable resources. I tried to do something like that with a custom adapter as well but it got a bit murky in part because the index would be effectively read only.

The Nova approach (just modifying behavior based on the Searchable trait) would be nice but Scout's Builder seems more limited so I couldn't come up with a straightforward way to e.g. use it as a simple drop-in replacement.

@lindyhopchris
Copy link
Contributor Author

lindyhopchris commented Feb 22, 2021

Well this new version is still in alpha, so it's not quite ready to be used. It's been re-written from the ground up and this new version is a lot better, but as I'm limited for time it means I can only really put new features into the new package, rather than the older one. So Scout integration will go into this package.

It's easier to ship custom index actions in this new version, the docs actually cover that already:
https://laraveljsonapi.io/docs/1.0/routing/writing-actions.html#fetch-many-aka-index

I've never used Scout so I'm going to have to get my head wrapped round it a bit to work out how best to actually integrate it. Off the top-of my head, it might be as easy as attaching Scout filters, so the integration knows if the client has used a Scout filter then it needs to use a Scout builder when querying the database. The filter implemetnation in the new package is described here:
https://laraveljsonapi.io/docs/1.0/schemas/filters.html

Would be good to hear your thoughts!

@ionut-tanasa
Copy link

Any updates on this one? Would love to have it integrated.

@lindyhopchris
Copy link
Contributor Author

This isn't top of my priorities tbh, because I've never used Scout and don't have a project where I would use it any time soon.

If there's someone who has Scout experience and would like to contribute, then I'd be happy to work with them on getting support in.

@ionut-tanasa
Copy link

@lindyhopchris i tried your suggestion above and did not work, i guess it is because Scout uses another query builder.

Creating a filter and then using it totally ignores the query.

Referring to $query->getModel()->search($value) in the apply() method.

I can always override FetchMany, but i would lose the other filters and scopes i have already defined on the UserSchema.

If i come up with a clean-enough solution for now i'll post it here.

Thanks for getting back to me anyway :)

@hamzamogni
Copy link

hello @ionut-tanasa , have you managed to find any solution? I am running into the same issue and trying to find a clean solution for this!

Thank you

@vrusua
Copy link

vrusua commented Jul 28, 2022

Hello everyone, is there any solution for this, or? Thanks.

@lindyhopchris
Copy link
Contributor Author

This is really tricky because it uses a different query builder, and we need the "normal" query builder to sort out things like eager loading (JSON:API include paths). I feel like it's going to need some significant refactoring to sort out. It needs someone to work out how in theory it should be implemented, as I don't have any Scout experience myself.

What needs to be worked out is how a developer would (outside of JSON:API) handle querying via Scout when you then need to apply eager loading, pagination, filters and only returning specific columns (sparse field-sets). I.e. if you were doing that on a standard controller (not a JSON:API one), how would you go about implementing it? What would your code look like? How would you test it?

If someone can come up with an approach that would work and can provide code examples, then I can do the bit of figuring how to incorporate that into Laravel JSON:API. Because I would love to support this in Laravel JSON:API, but I need someone with Scout experience to provide the code examples of how querying with all those other query parameters that a client can provide should actually work.

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

5 participants