fixed 如果有搜索关键字根据ES搜索结果排序
This commit is contained in:
parent
2668630f2a
commit
a03d1efcb0
|
@ -22,10 +22,12 @@ class Projects::ListQuery < ApplicationQuery
|
||||||
sort_direction = params[:sort_direction] || "desc"
|
sort_direction = params[:sort_direction] || "desc"
|
||||||
|
|
||||||
collection = optimize_sorting(collection, sort) if params[:category_id].present?
|
collection = optimize_sorting(collection, sort) if params[:category_id].present?
|
||||||
custom_sort(collection, sort, sort_direction)
|
# 如果有搜索关键字根据ES搜索结果排序
|
||||||
|
if params[:search].present? && @ids.present?
|
||||||
# scope = scope.reorder("projects.#{sort} #{sort_direction}")
|
collection.reorder(Arel.sql("FIELD(projects.id,#{@ids.join(',')})"))
|
||||||
# scope
|
else
|
||||||
|
custom_sort(collection, sort, sort_direction)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_projects(collection)
|
def filter_projects(collection)
|
||||||
|
@ -38,10 +40,10 @@ class Projects::ListQuery < ApplicationQuery
|
||||||
end
|
end
|
||||||
|
|
||||||
def by_search(items)
|
def by_search(items)
|
||||||
ids = Projects::ElasticsearchService.call(params[:search])
|
@ids = Projects::ElasticsearchService.call(params[:search])
|
||||||
items = items.where(platform: 'forge')
|
items = items.where(platform: 'forge')
|
||||||
if ids.present?
|
if @ids.present?
|
||||||
items = items.where(id: ids).by_name_or_identifier(params[:search])
|
items = items.where(id: @ids).by_name_or_identifier(params[:search])
|
||||||
else
|
else
|
||||||
items = items.by_name_or_identifier(params[:search])
|
items = items.by_name_or_identifier(params[:search])
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue