Added tag and hashtag filtering functionality
This commit is contained in:
parent
926c0f347a
commit
df8633e35c
|
|
@ -312,7 +312,7 @@ class SiteFeedAnnc
|
||||||
def self.get_feed_cache(
|
def self.get_feed_cache(
|
||||||
channel_key,merge_with_category=nil,
|
channel_key,merge_with_category=nil,
|
||||||
site_source=nil,locale=I18n.locale.to_s,
|
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
|
locale = I18n.locale.to_s
|
||||||
max_len = max_len.to_i
|
max_len = max_len.to_i
|
||||||
|
|
@ -339,6 +339,27 @@ class SiteFeedAnnc
|
||||||
match_cond = match_cond.merge(add_prefix(extra_match_cond))
|
match_cond = match_cond.merge(add_prefix(extra_match_cond))
|
||||||
end
|
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 = [
|
pipeline = [
|
||||||
{"$match" => match_cond},
|
{"$match" => match_cond},
|
||||||
{"$project"=>{"data"=>1}}
|
{"$project"=>{"data"=>1}}
|
||||||
|
|
@ -387,6 +408,12 @@ class SiteFeedAnnc
|
||||||
end
|
end
|
||||||
tmp
|
tmp
|
||||||
end
|
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
|
return feeds, feeds_count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue