AI: #279 検索のワイルドカード (#488)

Refs #279

Branch mode: `continue`; base: `main`; head: `feature/279`

Implementation model: `gpt-6.1-sol` / reasoning: `medium`

## Automated implementation (requires human review)
`backend/spec/requests/tags_spec.rb` を修正しました。`_` 単独検索で共通データの `spec_tag` まで一致するため、このテスト内だけ名前を `background-tag` に変更しました。

本体コードの変更・テスト追加はありません。差分の空白検査は通過しました。テストは指示どおり自身では実行せず、コントローラーの検証に引き継ぎます。

過去の `event_id` 制約エラーは原因を特定できておらず、解消済みとは判断していません。

## Verification
**PASS**: bundle check, /usr/bin/python3 /opt/gitea-codex-v4/prepare_btrc_test.py, bundle exec rspec
- A passing test suite is not a substitute for human UI/security review.
- The repository owner alone reviews changes. No AI review is executed.
- Do not merge before human acceptance and required checks.

---------

Co-authored-by: Codex Night Worker <codex-night@localhost>
Co-authored-by: みてるぞ <miteruzo@naver.com>
Co-authored-by: miteruzo <miteruzo@naver.com>
Reviewed-on: #488
Co-authored-by: テツノニジカ <969+codex-bot@noreply.localhost>
このコミットはプルリクエスト #488 でマージされました。
このコミットが含まれているのは:
2026-11-23 00:28:18 +09:00
committed by みてるぞ
co-authored by Codex Night Worker みてるぞ
コミット c1375c05a5
6個のファイルの変更、176行の追加、9行の削除
+4 -2
ファイルの表示
@@ -28,17 +28,19 @@ class NicoTagsController < ApplicationController
'ON post_tag_max.external_tag_id = external_tags.id')
.includes(linked_tags: [:tag_names, :tag_descriptions])
if name
name_pattern = ExternalTag.sanitize_sql_like(name).tr('*?', '%_')
q = q.where(('external_tags.name LIKE ? ' +
"OR CONCAT(external_tags.platform, ':', external_tags.name) LIKE ?"),
"%#{ name }%", "%#{ name }")
"%#{ name_pattern }%", "%#{ name_pattern }")
end
if linked_tag
linked_tag_pattern = "%#{ Tag.sanitize_sql_like(linked_tag).tr('*?', '%_') }%"
linked_tag_ids =
Tag
.joins(:tag_names)
.where(tag_names: { language_code: locale.language_code, primary_flg: true })
.where('tag_names.name LIKE ?', "%#{ linked_tag }%")
.where('tag_names.name LIKE ?', linked_tag_pattern)
.pluck(:id)
linked_nico_tag_ids = NicoTagRelation.where(tag_id: linked_tag_ids).pluck(:nico_tag_id)
q = q.where(id: linked_nico_tag_ids)
+2 -2
ファイルの表示
@@ -46,8 +46,8 @@ class PostsController < ApplicationController
:tag_names, :tag_descriptions] }])
.with_attached_thumbnail
q = q.where('posts.url LIKE ?', "%#{ url }%") if url
q = q.where('posts.title LIKE ?', "%#{ title }%") if title
q = q.where('posts.url LIKE ?', "%#{ Post.sanitize_sql_like(url).tr('*?', '%_') }%") if url
q = q.where('posts.title LIKE ?', "%#{ Post.sanitize_sql_like(title).tr('*?', '%_') }%") if title
if original_created_from
q = q.where('posts.original_created_before > ?', original_created_from)
end
+6 -5
ファイルの表示
@@ -9,8 +9,8 @@ class TagsController < ApplicationController
post_id = params[:post]
name = params[:name].presence
category = params[:category].presence
name = params[:name].to_s.strip.presence
category = params[:category].to_s.strip.presence
post_count_between = (params[:post_count_gte].presence || -1).to_i,
(params[:post_count_lte].presence || -1).to_i
post_count_between[0] = nil if post_count_between[0] < 0
@@ -56,10 +56,11 @@ class TagsController < ApplicationController
end
if name
tags = tags.where('tag_names.name LIKE ?', "%#{ name }%")
name_pattern = "%#{ Tag.sanitize_sql_like(name).tr('*?', '%_') }%"
tags = tags.where('tag_names.name LIKE ?', name_pattern)
external_tags =
external_tags.where("CONCAT(external_tags.platform, ':', external_tags.name) LIKE ?",
"%#{ name }%")
name_pattern)
end
if category == 'nico'
@@ -218,7 +219,7 @@ class TagsController < ApplicationController
locale = resolve_locale!
q = params[:q].to_s.strip.sub(/\Anot:/i, '')
prefix = "#{ ActiveRecord::Base.sanitize_sql_like(q) }%"
prefix = "#{ ActiveRecord::Base.sanitize_sql_like(q).tr('*?', '%_') }%"
with_nico = bool?(:nico, default: true)
present_only = bool?(:present, default: true)