Model#search: factor out post_tags_match.
This commit is contained in:
@@ -31,23 +31,11 @@ class Comment < ApplicationRecord
|
||||
where("comments.is_deleted = false")
|
||||
end
|
||||
|
||||
def post_tags_match(query)
|
||||
where(post_id: PostQueryBuilder.new(query).build.reorder(""))
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = super
|
||||
|
||||
q = q.attribute_matches(:body, params[:body_matches], index_column: :body_index)
|
||||
|
||||
if params[:post_id].present?
|
||||
q = q.where("post_id in (?)", params[:post_id].split(",").map(&:to_i))
|
||||
end
|
||||
|
||||
if params[:post_tags_match].present?
|
||||
q = q.post_tags_match(params[:post_tags_match])
|
||||
end
|
||||
|
||||
q = q.search_post_id_attribute(params)
|
||||
q = q.search_user_attribute(:creator, params)
|
||||
q = q.attribute_matches(:is_deleted, params[:is_deleted])
|
||||
q = q.attribute_matches(:is_sticky, params[:is_sticky])
|
||||
|
||||
Reference in New Issue
Block a user