3 changed files with 29 additions and 33 deletions
@ -0,0 +1,23 @@ |
|||||||
|
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 |
||||||
Loading…
Reference in new issue