我使用Searchkick搜索用户记录。我每次都得到相同的结果订单。我已经阅读了文档但找不到任何内容。以下是我正在使用的实现。
search_params = {}
search_params[:where] = where #where holds all the conditions for the search
search_params[:order] = {user_id: :desc}
user_matches = User.search "*", search_params
答案 0 :(得分:1)
铁路方式:
user_matches.results.shuffle
Searchkick方式:
seed = current_user.id
# setting seed to the user_id will make the random results consistent for that user...
# ... if you always want random results than you should make seed = Time.zone.now.to_i
User.search( "*", body: {query: {function_score: {random_score: {seed: seed}}}} )
对于searchkick方式,这里是elasticsearch reference
以下是Searchkick issues
中的另一个示例