related tags: fix AI tags not showing rating tags.

* Fix the suggested tags list in the related tags box not showing rating tags.
* Fix the suggested tags list showing tags that have been aliased to another tag.
This commit is contained in:
evazion
2022-07-02 19:05:12 -05:00
parent 483f311428
commit 9000fa63bc
4 changed files with 20 additions and 4 deletions

View File

@@ -58,7 +58,11 @@ class RelatedTagQuery
def ai_tags
return AITag.none if media_asset.nil?
media_asset.ai_tags.joins(:tag).undeprecated.nonempty.in_order_of(:"tags.category", TagCategory.canonical_mapping.values).order("ai_tags.score DESC, tags.name ASC").take(limit)
tags = media_asset.ai_tags.includes(:tag, :aliased_tag)
tags = tags.reject(&:is_deprecated?).reject { |t| t.empty? && !t.metatag? }
tags = tags.sort_by { |t| [TagCategory.canonical_mapping.keys.index(t.category_name), -t.score, t.name] }
tags.take(limit)
end
# Returns the top 20 most frequently added tags within the last 20 edits made by the user in the last hour.

View File

@@ -6,6 +6,7 @@ class AITag < ApplicationRecord
belongs_to :tag
belongs_to :media_asset
has_one :post, through: :media_asset
has_one :aliased_tag, through: :tag
validates :score, inclusion: { in: (0..100) }
@@ -14,7 +15,7 @@ class AITag < ApplicationRecord
scope :empty, -> { where(tag: Tag.empty) }
scope :nonempty, -> { where(tag: Tag.nonempty) }
delegate :name, :pretty_name, :post_count, :category, :category_name, to: :tag
delegate :name, :pretty_name, :post_count, :category, :category_name, :is_deprecated?, :empty?, :is_aliased?, :metatag?, to: :tag
def self.named(name)
name = $1.downcase if name =~ /\A(rating:.)/i

View File

@@ -9,6 +9,7 @@ class Tag < ApplicationRecord
has_one :wiki_page, :foreign_key => "title", :primary_key => "name"
has_one :artist, :foreign_key => "name", :primary_key => "name"
has_one :antecedent_alias, -> {active}, :class_name => "TagAlias", :foreign_key => "antecedent_name", :primary_key => "name"
has_one :aliased_tag, through: :antecedent_alias, source: :consequent_tag
has_many :consequent_aliases, -> {active}, :class_name => "TagAlias", :foreign_key => "consequent_name", :primary_key => "name"
has_many :antecedent_implications, -> {active}, :class_name => "TagImplication", :foreign_key => "antecedent_name", :primary_key => "name"
has_many :consequent_implications, -> {active}, :class_name => "TagImplication", :foreign_key => "consequent_name", :primary_key => "name"
@@ -405,6 +406,14 @@ class Tag < ApplicationRecord
end
end
def is_aliased?
aliased_tag.present?
end
def metatag?
name.match?(/\A#{PostQueryBuilder::METATAGS.join("|")}:/i)
end
def self.model_restriction(table)
super.where(table[:post_count].gt(0))
end

View File

@@ -5,12 +5,14 @@
</h3>
<ul class="tag-list simple-tag-list">
<% ai_tags.each do |t| %>
<% ai_tags.each do |ai_tag| %>
<li class="flex items-center space-x-1">
<input type="checkbox" tabindex="-1">
<span>
<% t = ai_tag.is_aliased? ? ai_tag.aliased_tag : ai_tag.tag %>
<%= link_to t.pretty_name, posts_path(tags: t.name), class: "search-tag tag-type-#{t.category}", "data-tag-name": t.name %>
<%= tag.span "#{t.score}%", class: "text-muted text-xs" %>
<%= tag.span "#{ai_tag.score}%", class: "text-muted text-xs" %>
</span>
</li>
<% end %>