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

Consistent random sorting #178

Closed
barrychc opened this issue Apr 8, 2014 · 4 comments
Closed

Consistent random sorting #178

barrychc opened this issue Apr 8, 2014 · 4 comments

Comments

@barrychc
Copy link

barrychc commented Apr 8, 2014

Hi @ankane,

I come up with a requirement of consistent random sorting and found that it is available in elasticsearch with the function_score query. May I know if this can be achieved with searchkick? Thanks.

Ref: http://www.elasticsearch.org/blog/0-90-4-released/

@ankane
Copy link
Owner

ankane commented Apr 8, 2014

You'll need to modify the query Searchkick generates.

query = Product.search "test", execute: false
query.body[:query] = # your code here
products = query.execute

@barrychc
Copy link
Author

barrychc commented Apr 9, 2014

Thank @ankane. However, I am currently getting stuck in v0.5.3 as I failed to update to v0.6.x due to failure to install a dependency "patron (0.4.18)" in windows machine. I am currently working on that and will keep you updated. Thanks again.

@ankane
Copy link
Owner

ankane commented Apr 9, 2014

Yikes, I didn't realize Patron's stance was "Windows users are on your own. Good luck with that." I'm going to remove that dependency on master.

@barrychc
Copy link
Author

barrychc commented Apr 9, 2014

Hi @ankane, thanks for removing Patron. It works well after updating to v0.6.3 with a sample code below:

irb(main):039:0> s = DateTime.now.to_i
=> 1397033506

query = Product.search "*", execute: false

irb(main):040:0> query.body[:query] = {function_score:{ random_score: { seed: s } } }
=> {:function_score=>{:random_score=>{:seed=>1397033506}}}

product = query.execute

Your help is highly appreciated.

@barrychc barrychc closed this as completed Apr 9, 2014
@lock lock bot locked as resolved and limited conversation to collaborators Dec 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants