mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Correct bad where clause when no category/user found
This commit is contained in:
@@ -215,13 +215,21 @@ class Search
|
||||
end
|
||||
|
||||
advanced_filter(/category:(.+)/) do |posts,match|
|
||||
category_id = Category.find_by('name ilike ? OR id = ?', match, match.to_i).try(:id)
|
||||
posts.where("topics.category_id = ?", category_id)
|
||||
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)
|
||||
else
|
||||
posts.where("1 = 0")
|
||||
end
|
||||
end
|
||||
|
||||
advanced_filter(/user:(.+)/) do |posts,match|
|
||||
user_id = User.find_by('username_lower = ? OR id = ?', match.downcase, match.to_i).try(:id)
|
||||
posts.where("posts.user_id = #{user_id}")
|
||||
user_id = User.where('username_lower = ? OR id = ?', match.downcase, match.to_i).pluck(:id).first
|
||||
if user_id
|
||||
posts.where("posts.user_id = #{user_id}")
|
||||
else
|
||||
posts.where("1 = 0")
|
||||
end
|
||||
end
|
||||
|
||||
advanced_filter(/min_age:(\d+)/) do |posts,match|
|
||||
|
||||
Reference in New Issue
Block a user