-
Notifications
You must be signed in to change notification settings - Fork 758
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
[WIP] Records order preservation ActiveRecord POC #639
Conversation
I've also made a pull request to solve this problem using a different and more performant way. #672 Of course milage may vary but I was using a method similar to one you are proposing here and the query time to bring by 25 records was ~100ms which is slow as you mentioned in the description. With what I'm proposing in my PR I was able to get the same 25 records in 0.7ms. Check it out and let me know if you have any thoughts on it. |
Hey @Mavvie, thanks for the PR. Here's how Elasticsearch Rails handles it. It should be a more performant approach. |
@ankane - Would the way ElasticSearch Rails handles it work for us when we paginate search results? |
This is an interesting problem. I'm working up a PR now and when writing the test I noticed that calling normal enumerable methods like |
Since we're returning an active record relation with Anyone else following me here? |
I think something similar is possible, but I'm not sure exactly how it would be implemented. I don't really know how pagination libraries work. It could make sense to do the ordering in Ruby-land if we're only loading |
Maybe you could try the order method le0pard shared here: khiav223577/find_with_order#5 |
@ankane maybe we could add that gem as a dependency? Or should we copy what we need from it? |
Hey, the plan is to remove the |
Fixes #463
As you know, currently the
records
method is not ordered by Elasticsearch'shit
ordering. Taking heavy inspiration fromorder_as_specified
gem, this preserves the order of the search results.It should be noted that this is quite slow to do, and should only be done if you really need an
ActiveRecord::Relation
. Otherwise, it's possibly better to just use the existing in-memory representation.Todo
results_query
preserves order for Mongoid/NoBrainerLet me know if you have any thoughts.
also, cc @abevoelker @milushov