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.
26 lines
861 B
26 lines
861 B
module SubjectSearch |
|
def search_subject(search_params) |
|
fulltext_fields = %i[name lineage_name].freeze |
|
|
|
search = ::Cdao::Subject.search do |
|
fulltext search_params[:q], fields: fulltext_fields if search_params[:q].present? |
|
|
|
fulltext_fields.each do |field| |
|
fulltext search_params[field], fields: %i[field], query_phrase_slop: 0, minimum_match: 1 |
|
end |
|
|
|
with :parent_id, search_params[:parent_id].to_i if search_params[:parent_id].present? |
|
|
|
without :parent_id if search_params[:is_root].present? && search_params[:is_root].to_s.eql?("true") |
|
|
|
without(:id).any_of(search_params[:exclude_ids]) if search_params[:exclude_ids].present? |
|
|
|
order_by :lineage_name, :asc |
|
order_by :name, :asc |
|
|
|
paginate page: search_params[:page] || 1, per_page: search_params[:per_page] || 20 |
|
end |
|
|
|
search |
|
end |
|
end
|
|
|