-
Notifications
You must be signed in to change notification settings - Fork 38
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
Searching multiple types/models #29
Comments
I'm very interested in the answer too, or functionality |
I would also like to know if this is possible. Thanks. |
Presently it's not possible in Elastiquent, it is however possible using ElasticSearch:
Changing Elasticquent to search multiple models at the same time will require a bit of modification (and also from the source level would not make sense, currently). https://github.com/adamfairholm/Elasticquent/blob/master/src/ElasticquentTrait.php#L244-L269
The problem here is that Searching multiple indexes at a time will require a new class that performs just a search, and somehow the collection that is returned should be able to differentiate between different models. Adding this would make the code more complex, and I can't see too many benefits due to adding it. |
Usually you don't build a Laravel app based only on one model. What happens if you have to search the whole site for something, is there any other way to do it? I tried making two different searches (on different types) and then use the merge() method to merge the returned collections, but it didn't work. |
I've tried to use merge() too, and doesn't work because is not the same method of \Illuminate\Support\Collection , what I have to do to merge the results was something like this:
|
OK, I will look into why the merging is not working a little later tonight, then. It definitely should be OK. |
Edit: I said I would look into why the merging is not working a little later tonight, but a quick check shows why merge will not work.
The @alfchee this will mean in your case that when you are attempting to merge This brings me back to my original comment:
The best way to do this might be to create a new Facade (called |
+1 for alfchee's method. I needed to show results from different tables: Articles, Blog entries, Deals, etc. And I needed to display them in order of relevance score, regardless of the type of document. For sorting based on the documentScore: $result->sortByDesc(function ($item){ |
I too would find a nice solution very valuable, as like some said earlier, many Laravel apps are built on many models, with relationships etc. Anyhow, I got around this using alfchee's method above. It's a little hacky, but it get's my results and I've also grouped them so I can later iterate and "break up" my search results by type etc...
|
I wrote basic && useful function. You can edit search filters or query in if blocks.
and you can call with:
|
Is it possible to search multiple types/models at the same time with Elasticquent?
The text was updated successfully, but these errors were encountered: