From df8633e35cb39620e1abb55f985c920957534f2d Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 11 Feb 2026 10:04:24 +0000 Subject: [PATCH] Added tag and hashtag filtering functionality --- app/models/site_feed_annc.rb | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/app/models/site_feed_annc.rb b/app/models/site_feed_annc.rb index fca476c..7f0832d 100644 --- a/app/models/site_feed_annc.rb +++ b/app/models/site_feed_annc.rb @@ -312,7 +312,7 @@ class SiteFeedAnnc def self.get_feed_cache( channel_key,merge_with_category=nil, site_source=nil,locale=I18n.locale.to_s, - is_widget=false,max_len=nil,sort_maps=nil,extra_match_cond=nil + is_widget=false,max_len=nil,sort_maps=nil,extra_match_cond=nil,tags=nil,hashtags=nil ) locale = I18n.locale.to_s max_len = max_len.to_i @@ -339,6 +339,27 @@ class SiteFeedAnnc match_cond = match_cond.merge(add_prefix(extra_match_cond)) end + if tags.present? && tags != ["all"] && tags != "all" + tag_names = Tag.where(:id.in => Array(tags)).map(&:name).reject(&:blank?) + if tag_names.present? + tag_query = { + "$or" => tag_names.map { |t| + [ + { "data.tags.name_translations.#{locale}" => t }, + { "data.tags.name_translations.zh_tw" => t } + ] + }.flatten + } + + match_cond = match_cond.merge(tag_query) + end + end + + if hashtags.present? && hashtags != "all" + hashtag_query = { "data.orbithashtags.name" => { "$in" => Array(hashtags) } } + match_cond = match_cond.merge(hashtag_query) + end + pipeline = [ {"$match" => match_cond}, {"$project"=>{"data"=>1}} @@ -387,6 +408,12 @@ class SiteFeedAnnc end tmp end + + if (tags.present? && tags != "all") || (hashtags.present? && hashtags != "all") + feeds = feeds.uniq { |f| f['id'] } + feeds_count = feeds.size + end + return feeds, feeds_count end