First pass

This commit is contained in:
James Kiesel
2016-08-11 01:38:16 -04:00
parent 823a699d41
commit 7e73b933c7
7 changed files with 43 additions and 6 deletions

View File

@@ -20,6 +20,7 @@ class TopicQuery
visible
category
tags
match_all_tags
no_tags
order
ascending
@@ -460,11 +461,21 @@ class TopicQuery
if @options[:tags] && @options[:tags].size > 0
result = result.joins(:tags)
# ANY of the given tags:
if @options[:tags][0].is_a?(Integer)
result = result.where("tags.id in (?)", @options[:tags])
# ALL of the given tags:
if @options[:match_all_tags]
@options[:tags] = Tag.where(name: @options[:tags]).pluck(:id) unless @options[:tags][0].is_a?(Integer)
@options[:tags].each_with_index do |tag, index|
sql_alias = ['t', index].join
result = result.joins("INNER JOIN topic_tags #{sql_alias} ON #{sql_alias}.topic_id = topics.id AND #{sql_alias}.tag_id = #{tag}")
end
else
result = result.where("tags.name in (?)", @options[:tags])
# ANY of the given tags:
if @options[:tags][0].is_a?(Integer)
result = result.where("tags.id in (?)", @options[:tags])
else
result = result.where("tags.name in (?)", @options[:tags])
end
end
elsif @options[:no_tags]
# the following will do: ("topics"."id" NOT IN (SELECT DISTINCT "topic_tags"."topic_id" FROM "topic_tags"))