mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Merge pull request #4896 from dmacjam/multiple-tags-logical-and-search
FEATURE: Advanced search supports logical AND of multiple tags
This commit is contained in:
@@ -447,15 +447,27 @@ class Search
|
||||
end
|
||||
end
|
||||
|
||||
advanced_filter(/tags?:([a-zA-Z0-9,\-_]+)/) do |posts, match|
|
||||
tags = match.split(",")
|
||||
advanced_filter(/tags?:([a-zA-Z0-9,\-_+]+)/) do |posts, match|
|
||||
if match.include?('+')
|
||||
tags = match.split('+')
|
||||
|
||||
posts.where("topics.id IN (
|
||||
posts.where("topics.id IN (
|
||||
SELECT tt.topic_id
|
||||
FROM topic_tags tt, tags
|
||||
WHERE tt.tag_id = tags.id
|
||||
GROUP BY tt.topic_id
|
||||
HAVING to_tsvector(#{query_locale}, array_to_string(array_agg(tags.name), ' ')) @@ to_tsquery(#{query_locale}, ?)
|
||||
)", tags.join('&'))
|
||||
else
|
||||
tags = match.split(",")
|
||||
|
||||
posts.where("topics.id IN (
|
||||
SELECT DISTINCT(tt.topic_id)
|
||||
FROM topic_tags tt, tags
|
||||
WHERE tt.tag_id = tags.id
|
||||
AND tags.name in (?)
|
||||
)", tags)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Reference in New Issue
Block a user