parent
122ef893c9
commit
cb8dd3dc9f
@ -1,9 +1,12 @@
|
|||||||
class SearchsController < ApplicationController
|
class SearchsController < ApplicationController
|
||||||
|
after_action :record_search_keyword, only: [:index]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@results = SearchService.call(search_params)
|
@results = SearchService.call(search_params)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def search_params
|
def search_params
|
||||||
params.permit(:keyword, :type, :page, :per_page)
|
params.permit(:keyword, :type, :page, :per_page)
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
class Weapps::HotKeywordsController < Weapps::BaseController
|
||||||
|
def index
|
||||||
|
keywords = []
|
||||||
|
keywords = HotSearchKeyword.hot(8) if HotSearchKeyword.available?
|
||||||
|
render_ok(keywords: keywords)
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,13 @@
|
|||||||
|
class Weapps::SearchsController < Weapps::BaseController
|
||||||
|
after_action :record_search_keyword, only: [:index]
|
||||||
|
|
||||||
|
def index
|
||||||
|
@results = Weapps::SearchQuery.call(search_params)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def search_params
|
||||||
|
params.permit(:keyword, :type, :page, :per_page)
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,37 @@
|
|||||||
|
class Weapps::SearchQuery < ApplicationQuery
|
||||||
|
include ElasticsearchAble
|
||||||
|
|
||||||
|
attr_reader :params
|
||||||
|
|
||||||
|
def initialize(params)
|
||||||
|
@params = params
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
modal_name.search(keyword, search_options)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def search_options
|
||||||
|
hash = {
|
||||||
|
fields: [:name],
|
||||||
|
page: page,
|
||||||
|
per_page: per_page
|
||||||
|
}
|
||||||
|
hash.merge(where: { status: 2 }) if modal_name == Shixun
|
||||||
|
|
||||||
|
hash
|
||||||
|
end
|
||||||
|
|
||||||
|
def modal_name
|
||||||
|
@_modal_name ||= begin
|
||||||
|
case params[:type].to_s
|
||||||
|
when 'subject' then Subject
|
||||||
|
when 'shixun' then Shixun
|
||||||
|
when 'course' then Course
|
||||||
|
else Subject
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,9 @@
|
|||||||
|
json.count @results.total_count
|
||||||
|
json.results do
|
||||||
|
json.array! @results.with_highlights(multiple: true) do |obj, highlights|
|
||||||
|
json.merge! obj.to_searchable_json
|
||||||
|
json.type obj.class.name.downcase
|
||||||
|
|
||||||
|
json.title highlights.delete(:name)&.join('...') || obj.searchable_title
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in new issue