|
|
|
@@ -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 |
|
|
|
|