| @@ -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) | |||||
| # 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 | 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? | |||||
| 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 | else | ||||
| items = items.by_name_or_identifier(params[:search]) | items = items.by_name_or_identifier(params[:search]) | ||||
| end | end | ||||