fixed 如果有搜索关键字根据ES搜索结果排序

This commit is contained in:
xxq250 2023-02-02 14:05:40 +08:00
parent 2668630f2a
commit a03d1efcb0
1 changed files with 9 additions and 7 deletions

View File

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