forked from Trustie/forgeplus
fixed 项目搜索先es search
This commit is contained in:
parent
7f91ebb509
commit
3ff3502bbc
|
@ -25,7 +25,7 @@ class Projects::ListQuery < ApplicationQuery
|
|||
|
||||
def filter_projects(collection)
|
||||
# collection = by_pinned(collection)
|
||||
collection = by_search(collection)
|
||||
collection = by_search(collection) if params[:search].present?
|
||||
collection = by_project_type(collection)
|
||||
collection = by_project_category(collection)
|
||||
collection = by_project_language(collection)
|
||||
|
@ -33,7 +33,12 @@ class Projects::ListQuery < ApplicationQuery
|
|||
end
|
||||
|
||||
def by_search(items)
|
||||
items.visible.by_name_or_identifier(params[:search])
|
||||
ids = Projects::ElasticsearchService.call(params[:search])
|
||||
if ids.present?
|
||||
items.visible.where(id: ids)
|
||||
else
|
||||
items.visible.by_name_or_identifier(params[:search])
|
||||
end
|
||||
end
|
||||
|
||||
def by_project_type(items)
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
class Projects::ElasticsearchService < ApplicationService
|
||||
attr_reader :keyword
|
||||
|
||||
def initialize(keyword)
|
||||
@keyword = keyword
|
||||
end
|
||||
|
||||
def call
|
||||
domain = EduSetting.get("search_api_url") || "https://statistics.gitlink.org.cn"
|
||||
api_url = "#{domain}/search?page=1&size=1000&term=#{@keyword}&type=1"
|
||||
response = Faraday.get(api_url)
|
||||
result = JSON.parse(response&.body)
|
||||
project_ids = result[:data][:rows].map{|d|d[:instanceId]}
|
||||
project_ids
|
||||
rescue => e
|
||||
puts "ElasticsearchService error: #{e.message}"
|
||||
raise Error, e.message
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue