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.
41 lines
787 B
41 lines
787 B
5 years ago
|
module ElasticsearchAble
|
||
|
extend ActiveSupport::Concern
|
||
|
|
||
|
private
|
||
|
|
||
|
def default_options
|
||
|
{
|
||
|
debug: Rails.env.development?,
|
||
|
highlight: highlight_options,
|
||
|
body_options: body_options,
|
||
|
page: page,
|
||
|
per_page: per_page
|
||
|
}
|
||
|
end
|
||
|
|
||
|
def keyword
|
||
|
params[:keyword].to_s.strip.presence || '*'
|
||
|
end
|
||
|
|
||
|
def highlight_options
|
||
|
{
|
||
|
fragment_size: EduSetting.get('es_highlight_fragment_size') || 30,
|
||
|
tag: '<span>'
|
||
|
}
|
||
|
end
|
||
|
|
||
|
def body_options
|
||
|
{
|
||
|
min_score: EduSetting.get('es_min_score') || 10
|
||
|
}
|
||
|
end
|
||
|
|
||
|
def per_page
|
||
|
per_page = params[:per_page].to_s.strip.presence || params[:limit].to_s.strip.presence
|
||
|
per_page.to_i <= 0 ? 20 : per_page.to_i
|
||
|
end
|
||
|
|
||
|
def page
|
||
|
params[:page].to_i <= 0 ? 1 : params[:page].to_i
|
||
|
end
|
||
|
end
|