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:
Neil Lalonde
2017-06-14 14:39:23 -04:00
committed by GitHub
5 changed files with 56 additions and 15 deletions

View File

@@ -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