mirror of
https://github.com/discourse/discourse.git
synced 2025-04-30 05:04:36 +08:00
Add searching by all tags using postgres full-text search.
This commit is contained in:
parent
6d1fafaff6
commit
3eebcccbf2
@ -445,9 +445,21 @@ class Search
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
advanced_filter(/tags?:([a-zA-Z0-9,\-_]+)/) do |posts, match|
|
advanced_filter(/tags?:([a-zA-Z0-9,\-_|]+)/) do |posts, match|
|
||||||
|
if match.include?(',')
|
||||||
tags = match.split(",")
|
tags = match.split(",")
|
||||||
|
|
||||||
|
# TODO use ts_query function
|
||||||
|
posts.where("topics.id IN (
|
||||||
|
SELECT DISTINCT(tt.topic_id)
|
||||||
|
FROM topic_tags tt, tags
|
||||||
|
WHERE tt.tag_id = tags.id
|
||||||
|
GROUP BY tt.topic_id
|
||||||
|
HAVING to_tsvector('simple',array_to_string(array_agg(tags.name), ' ')) @@ to_tsquery('simple', ?)
|
||||||
|
)", tags.join('&'))
|
||||||
|
else
|
||||||
|
tags = match.split("|")
|
||||||
|
|
||||||
posts.where("topics.id IN (
|
posts.where("topics.id IN (
|
||||||
SELECT DISTINCT(tt.topic_id)
|
SELECT DISTINCT(tt.topic_id)
|
||||||
FROM topic_tags tt, tags
|
FROM topic_tags tt, tags
|
||||||
@ -455,6 +467,7 @@ class Search
|
|||||||
AND tags.name in (?)
|
AND tags.name in (?)
|
||||||
)", tags)
|
)", tags)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user