If you search a category by id, also include its children

This commit is contained in:
Robin Ward
2016-06-08 13:50:33 -04:00
parent e393e43ce5
commit b9df18360d
2 changed files with 9 additions and 6 deletions

View File

@ -275,9 +275,9 @@ class Search
end
advanced_filter(/category:(.+)/) do |posts,match|
category_id = Category.where('name ilike ? OR id = ?', match, match.to_i).pluck(:id).first
if category_id
posts.where("topics.category_id = ?", category_id)
category_ids = Category.where('name ilike ? OR id = ? OR parent_category_id = ?', match, match.to_i, match.to_i).pluck(:id)
if category_ids.present?
posts.where("topics.category_id IN (?)", category_ids)
else
posts.where("1 = 0")
end