Browse Source

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

pull/342/head
xxq250 3 years ago
parent
commit
a03d1efcb0
1 changed files with 9 additions and 7 deletions
  1. +9
    -7
      app/queries/projects/list_query.rb

+ 9
- 7
app/queries/projects/list_query.rb 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


Loading…
Cancel
Save