Rails ActsAsTaggableOn,按相似标签的数量对结果"tagged_with"排名



我有一个包含业务、类别和阶段标记类型的Classs模型。

classs.rb:

acts_as_taggable_on :businesses
acts_as_taggable_on :categories
acts_as_taggable_on :stages
BUSINESSES = [
"Service Professional (Financial Advisor, Realtor, etc.)",
"E-Commerce",
"F&B",
"Education & Coaching",
"Start-ups",
"B2B",
"B2C",
"Others"
]
CATEGORIES = [
"Social Media Marketing",
"Lead Generation",
"Content Strategy",
"Marketing Strategy",
"Branding Strategy"
]
STAGES = [
"Development (Little to no revenue)",
"Early (Small customer base with some market presence)",
"Growth (Established customer base and large amount of revenue)",
"Mature (Large customer base and profits)"
]

以及一个ClassSearch表单,用户可以在其中分别输入他们的业务、类别和阶段,搜索Classses。

class_searches_controller#show

@filter = @class_search.categories.push(@class_search.business).push(@class_search.stage).flatten.reject(&:blank?)
@classses = Classs.all.tagged_with(@filter, any: true)

我想知道是否可以根据类似@class_search的标签数量对@classses进行排序。如果我没有错的话,acts_as_tagtable_on根据ID对结果进行排名,这在这种情况下没有太大帮助。

提前感谢:D

这是可以传递给tagged_with方法的可用选项之一。

@classses = Classs.all.tagged_with(@filter, any: true, order_by_matching_tag_count: true)

应该为您提供一个按匹配标签数量排序(降序(的列表。

最新更新