You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
764 B
39 lines
764 B
5 years ago
|
class SearchService < ApplicationService
|
||
|
include ElasticsearchAble
|
||
|
|
||
|
attr_reader :params
|
||
|
|
||
|
def initialize(params)
|
||
|
@params = params
|
||
|
end
|
||
|
|
||
|
def call
|
||
|
Searchkick.search(keyword, search_options)
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def search_options
|
||
|
{
|
||
|
index_name: index_names,
|
||
|
model_includes: model_includes
|
||
|
}.merge(default_options)
|
||
|
end
|
||
|
|
||
|
def index_names
|
||
|
@_index_names ||=
|
||
|
case params[:type].to_s.strip
|
||
|
when 'shixun' then [Shixun]
|
||
|
when 'course' then [Course]
|
||
|
when 'subject' then [Subject]
|
||
|
when 'memo' then [Memo]
|
||
|
else [Shixun, Course, Subject, Memo]
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def model_includes
|
||
|
index_names.each_with_object({}) do |klass, obj|
|
||
|
obj[klass] = klass.searchable_includes
|
||
|
end
|
||
|
end
|
||
|
end
|