This commit is contained in:
2026-04-02 01:43:39 +09:00
parent c28326b941
commit 6ed7f81151
10 changed files with 278 additions and 103 deletions
+33 -1
View File
@@ -37,7 +37,7 @@ class TagsController < ApplicationController
q = q.where(posts: { id: post_id }) if post_id.present?
q = q.where('tag_names.name LIKE ?', "%#{ name }%") if name
q = q.where(category: category) if category
q = q.where(category:) if category
q = q.where('tags.post_count >= ?', post_count_between[0]) if post_count_between[0]
q = q.where('tags.post_count <= ?', post_count_between[1]) if post_count_between[1]
q = q.where('tags.created_at >= ?', created_between[0]) if created_between[0]
@@ -69,6 +69,38 @@ class TagsController < ApplicationController
render json: { tags: TagRepr.base(tags), count: q.size }
end
def with_depth
parent_tag_id = params[:parent].to_i
parent_tag_id = nil if parent_tag_id <= 0
tag_ids =
if parent_tag_id
TagImplication.where(parent_tag_id:).select(:tag_id)
else
Tag.where.not(id: TagImplication.select(:tag_id)).select(:id)
end
tags =
Tag
.joins(:tag_name)
.includes(:tag_name, tag_name: :wiki_page)
.where(id: tag_ids)
.order('tag_names.name')
.distinct
.to_a
has_children_tag_ids =
if tags.empty?
[]
else
TagImplication.where(parent_tag_id: tags.map(&:id)).distinct.pluck(:parent_tag_id)
end
render json: tags.map { |tag|
TagRepr.base(tag).merge(has_children: has_children_tag_ids.include?(tag.id), children: [])
}
end
def autocomplete
q = params[:q].to_s.strip.sub(/\Anot:/i, '')