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.
 
 
 
 
 

23 lines
789 B

module DoctrineSearch
def doctrine_search(search_params)
fulltext_fields = %i[content].freeze
search = ::Doctrine.search do
fulltext search_params[:q], fields: fulltext_fields if search_params[:q].present?
with(:subject_ids).any_of(search_params[:subject_ids]) if search_params[:subject_ids].present?
with(:user_ids).any_of(search_params[:user_ids]) if search_params[:user_ids].present?
if search_params[:created_at].present?
with(:created_at).between(Date.parse(search_params[:created_at])..Time.zone.today.to_date)
end
without(:id).any_of(search_params[:exclude_ids]) if search_params[:exclude_ids].present?
paginate page: search_params[:page] || 1, per_page: search_params[:per_page] || 20
end
search
end
end