仿照 RubyChina,SearchController 如下:
class SearchController < ApplicationController
def index
search_params = {
sort: [
{updated_at: {order: "desc", ignore_unmapped: true}}
],
query: {
multi_match: {
query: params[:q],
fields: ['title', 'body', 'name', 'login'],
fuzziness: 2,
prefix_length: 5,
operator: :and
}
},
highlight: {
pre_tags: ["[h]"],
post_tags: ["[/h]"],
fields: {title: {}, body: {}, name: {}, login: {}}
}
}
@result = Elasticsearch::Model.search(search_params, [User, Page, Topic]).paginate(page: params[:page], per_page: 30)
end
end
我想实现:出来的结果是保持 User, Page, Topic 的顺序,如何 Topic 里面按照 updated_at 排序。试了好多方法,不得其法,特来求解。
目前只能让 user 排在最前面,Page 和 Topic 就混乱了。