コミットを比較

..

20 コミット

作成者 SHA1 メッセージ 日付
みてるぞ 409498729a Merge remote-tracking branch 'origin/main' into feature/206 2026-03-08 23:12:35 +09:00
みてるぞ f7af5efaf9 #206 エラー修正 2026-03-08 23:06:10 +09:00
みてるぞ 4235903b49 #206 updated_at の並び順修正 2026-03-08 22:58:22 +09:00
みてるぞ 17ff0e8114 Merge remote-tracking branch 'origin/main' into feature/206 2026-03-08 16:30:56 +09:00
みてるぞ 6b1079fc1a Merge branch 'main' into feature/206 2026-03-07 13:58:59 +09:00
みてるぞ a66a73e004 Merge branch 'main' into feature/206 2026-03-05 23:10:45 +09:00
みてるぞ 95ea097636 Merge branch 'main' into feature/206 2026-03-05 21:38:49 +09:00
みてるぞ da45bc95eb #206 2026-03-03 00:35:31 +09:00
みてるぞ 55dcd4e1f3 #206 2026-03-02 23:29:22 +09:00
みてるぞ 1e54fb5be4 #206 2026-03-02 22:40:55 +09:00
みてるぞ 1350ae3d99 #206 2026-03-01 15:05:40 +09:00
みてるぞ a088503272 #206 2026-03-01 13:48:47 +09:00
みてるぞ f8d2d753fe #206 タグ補完追加 2026-03-01 12:20:49 +09:00
みてるぞ 7d554e3950 #206 2026-02-26 23:53:08 +09:00
みてるぞ 4b447e952b #206 2026-02-26 23:33:09 +09:00
みてるぞ c3aa8bc580 #206 2026-02-26 12:43:31 +09:00
みてるぞ 663206c14c #206 2026-02-26 06:48:28 +09:00
みてるぞ 3e5eb4687b #206 2026-02-25 00:56:37 +09:00
みてるぞ 2a412b589f Merge remote-tracking branch 'origin/main' into feature/206 2026-02-24 21:29:36 +09:00
みてるぞ 498f215538 #206 2026-02-23 18:52:09 +09:00
4個のファイルの変更20行の追加173行の削除
+6 -28
ファイルの表示
@@ -245,40 +245,18 @@ class PostsController < ApplicationController
end end
def filter_posts_by_tags tag_names, match_type def filter_posts_by_tags tag_names, match_type
literals = tag_names.map do |raw_name| tag_names = TagName.canonicalise(tag_names)
{ name: TagName.canonicalise(raw_name.sub(/\Anot:/i, '')).first,
negative: raw_name.downcase.start_with?('not:') }
end
return Post.all if literals.empty? posts = Post.joins(tags: :tag_name)
if match_type == 'any' if match_type == 'any'
literals.reduce(Post.none) do |posts, literal| posts.where(tag_names: { name: tag_names }).distinct
posts.or(tag_literal_relation(literal[:name], negative: literal[:negative]))
end
else else
literals.reduce(Post.all) do |posts, literal| posts.where(tag_names: { name: tag_names })
ids = tagged_post_ids_for(literal[:name]) .group('posts.id')
if literal[:negative] .having('COUNT(DISTINCT tag_names.id) = ?', tag_names.uniq.size)
posts.where.not(id: ids)
else
posts.where(id: ids)
end end
end end
end
end
def tag_literal_relation name, negative:
ids = tagged_post_ids_for(name)
if negative
Post.where.not(id: ids)
else
Post.where(id: ids)
end
end
def tagged_post_ids_for(name) =
Post.joins(tags: :tag_name).where(tag_names: { name: }).select(:id)
def sync_post_tags! post, desired_tags def sync_post_tags! post, desired_tags
desired_tags.each do |t| desired_tags.each do |t|
+2 -1
ファイルの表示
@@ -17,7 +17,8 @@ class TagsController < ApplicationController
end end
def autocomplete def autocomplete
q = params[:q].to_s.strip.sub(/\Anot:/i, '') q = params[:q].to_s.strip
return render json: [] if q.blank?
with_nico = bool?(:nico, default: true) with_nico = bool?(:nico, default: true)
present_only = bool?(:present, default: true) present_only = bool?(:present, default: true)
+7 -124
ファイルの表示
@@ -16,7 +16,7 @@ RSpec.describe 'Posts API', type: :request do
end end
let!(:tag_name) { TagName.create!(name: 'spec_tag') } let!(:tag_name) { TagName.create!(name: 'spec_tag') }
let!(:tag) { Tag.create!(tag_name: tag_name, category: :general) } let!(:tag) { Tag.create!(tag_name: tag_name, category: 'general') }
let!(:post_record) do let!(:post_record) do
Post.create!(title: 'spec post', url: 'https://example.com/spec').tap do |p| Post.create!(title: 'spec post', url: 'https://example.com/spec').tap do |p|
@@ -28,9 +28,9 @@ RSpec.describe 'Posts API', type: :request do
let!(:user) { create_member_user! } let!(:user) { create_member_user! }
let!(:tag_name) { TagName.create!(name: "spec_tag") } let!(:tag_name) { TagName.create!(name: "spec_tag") }
let!(:tag) { Tag.create!(tag_name:, category: :general) } let!(:tag) { Tag.create!(tag_name:, category: "general") }
let!(:tag_name2) { TagName.create!(name: 'unko') } let!(:tag_name2) { TagName.create!(name: 'unko') }
let!(:tag2) { Tag.create!(tag_name: tag_name2, category: :deerjikist) } let!(:tag2) { Tag.create!(tag_name: tag_name2, category: 'deerjikist') }
let!(:alias_tag_name) { TagName.create!(name: 'manko', canonical: tag_name) } let!(:alias_tag_name) { TagName.create!(name: 'manko', canonical: tag_name) }
let!(:hit_post) do let!(:hit_post) do
@@ -116,123 +116,6 @@ RSpec.describe 'Posts API', type: :request do
end end
end end
context 'when tags contain not:' do
let!(:foo_tag_name) { TagName.create!(name: 'not_spec_foo') }
let!(:foo_tag) { Tag.create!(tag_name: foo_tag_name, category: :general) }
let!(:bar_tag_name) { TagName.create!(name: 'not_spec_bar') }
let!(:bar_tag) { Tag.create!(tag_name: bar_tag_name, category: :general) }
let!(:baz_tag_name) { TagName.create!(name: 'not_spec_baz') }
let!(:baz_tag) { Tag.create!(tag_name: baz_tag_name, category: :general) }
let!(:foo_alias_tag_name) do
TagName.create!(name: 'not_spec_foo_alias', canonical: foo_tag_name)
end
let!(:foo_only_post) do
Post.create!(uploaded_user: user, title: 'foo only',
url: 'https://example.com/not-spec-foo').tap do |p|
PostTag.create!(post: p, tag: foo_tag)
end
end
let!(:bar_only_post) do
Post.create!(uploaded_user: user, title: 'bar only',
url: 'https://example.com/not-spec-bar').tap do |p|
PostTag.create!(post: p, tag: bar_tag)
end
end
let!(:baz_only_post) do
Post.create!(uploaded_user: user, title: 'baz only',
url: 'https://example.com/not-spec-baz').tap do |p|
PostTag.create!(post: p, tag: baz_tag)
end
end
let!(:foo_bar_post) do
Post.create!(uploaded_user: user, title: 'foo bar',
url: 'https://example.com/not-spec-foo-bar').tap do |p|
PostTag.create!(post: p, tag: foo_tag)
PostTag.create!(post: p, tag: bar_tag)
end
end
let!(:foo_baz_post) do
Post.create!(uploaded_user: user, title: 'foo baz',
url: 'https://example.com/not-spec-foo-baz').tap do |p|
PostTag.create!(post: p, tag: foo_tag)
PostTag.create!(post: p, tag: baz_tag)
end
end
let(:controlled_ids) do
[foo_only_post.id, bar_only_post.id, baz_only_post.id,
foo_bar_post.id, foo_baz_post.id]
end
it 'supports not search' do
get '/posts', params: { tags: 'not:not_spec_foo' }
expect(response).to have_http_status(:ok)
expect(json.fetch('posts').map { |p| p['id'] } & controlled_ids).to match_array(
[bar_only_post.id, baz_only_post.id]
)
end
it 'supports alias in not search' do
get '/posts', params: { tags: 'not:not_spec_foo_alias' }
expect(response).to have_http_status(:ok)
expect(json.fetch('posts').map { |p| p['id'] } & controlled_ids).to match_array(
[bar_only_post.id, baz_only_post.id]
)
end
it 'treats multiple not terms as AND when match is omitted' do
get '/posts', params: { tags: 'not:not_spec_foo not:not_spec_bar' }
expect(response).to have_http_status(:ok)
expect(json.fetch('posts').map { |p| p['id'] } & controlled_ids).to match_array(
[baz_only_post.id]
)
end
it 'treats multiple not terms as OR when match=any' do
get '/posts', params: { tags: 'not:not_spec_foo not:not_spec_bar', match: 'any' }
expect(response).to have_http_status(:ok)
expect(json.fetch('posts').map { |p| p['id'] } & controlled_ids).to match_array(
[foo_only_post.id, bar_only_post.id, baz_only_post.id, foo_baz_post.id]
)
end
it 'supports mixed positive and negative search with AND' do
get '/posts', params: { tags: 'not_spec_foo not:not_spec_bar' }
expect(response).to have_http_status(:ok)
expect(json.fetch('posts').map { |p| p['id'] } & controlled_ids).to match_array(
[foo_only_post.id, foo_baz_post.id]
)
end
it 'supports mixed positive and negative search with OR when match=any' do
get '/posts', params: { tags: 'not_spec_foo not:not_spec_bar', match: 'any' }
expect(response).to have_http_status(:ok)
expect(json.fetch('posts').map { |p| p['id'] } & controlled_ids).to match_array(
[foo_only_post.id, baz_only_post.id, foo_bar_post.id, foo_baz_post.id]
)
end
end
context 'when url is provided' do context 'when url is provided' do
let!(:url_hit_post) do let!(:url_hit_post) do
Post.create!(uploaded_user: user, title: 'url hit', Post.create!(uploaded_user: user, title: 'url hit',
@@ -526,7 +409,7 @@ RSpec.describe 'Posts API', type: :request do
context "when nico tag already exists in tags" do context "when nico tag already exists in tags" do
before do before do
Tag.find_or_create_by!(tag_name: TagName.find_or_create_by!(name: 'nico:nico_tag'), Tag.find_or_create_by!(tag_name: TagName.find_or_create_by!(name: 'nico:nico_tag'),
category: :nico) category: 'nico')
end end
it 'return 400' do it 'return 400' do
@@ -592,7 +475,7 @@ RSpec.describe 'Posts API', type: :request do
# 追加で別タグも作って、更新時に入れ替わることを見る # 追加で別タグも作って、更新時に入れ替わることを見る
tn2 = TagName.create!(name: 'spec_tag_2') tn2 = TagName.create!(name: 'spec_tag_2')
Tag.create!(tag_name: tn2, category: :general) Tag.create!(tag_name: tn2, category: 'general')
put "/posts/#{post_record.id}", params: { put "/posts/#{post_record.id}", params: {
title: 'updated title', title: 'updated title',
@@ -611,7 +494,7 @@ RSpec.describe 'Posts API', type: :request do
context "when nico tag already exists in tags" do context "when nico tag already exists in tags" do
before do before do
Tag.find_or_create_by!(tag_name: TagName.find_or_create_by!(name: 'nico:nico_tag'), Tag.find_or_create_by!(tag_name: TagName.find_or_create_by!(name: 'nico:nico_tag'),
category: :nico) category: 'nico')
end end
it 'return 400' do it 'return 400' do
@@ -648,7 +531,7 @@ RSpec.describe 'Posts API', type: :request do
it 'returns add/remove events (history) for a post' do it 'returns add/remove events (history) for a post' do
# add # add
tn2 = TagName.create!(name: 'spec_tag2') tn2 = TagName.create!(name: 'spec_tag2')
tag2 = Tag.create!(tag_name: tn2, category: :general) tag2 = Tag.create!(tag_name: tn2, category: 'general')
pt = PostTag.create!(post: post_record, tag: tag2, created_user: member) pt = PostTag.create!(post: post_record, tag: tag2, created_user: member)
# remove (discard) # remove (discard)
+4 -19
ファイルの表示
@@ -56,11 +56,8 @@ export default (() => {
if (activeIndex < 0) if (activeIndex < 0)
break break
ev.preventDefault () ev.preventDefault ()
{
const selected = suggestions[activeIndex] const selected = suggestions[activeIndex]
if (selected) selected && handleTagSelect (selected)
handleTagSelect (selected)
}
break break
case 'Escape': case 'Escape':
@@ -70,25 +67,14 @@ export default (() => {
} }
if (ev.key === 'Enter' && (!(suggestionsVsbl) || activeIndex < 0)) if (ev.key === 'Enter' && (!(suggestionsVsbl) || activeIndex < 0))
{ {
const parts = search.split (' ') navigate (`/posts?${ (new URLSearchParams ({ tags: search })).toString () }`)
const match = parts.map (t => t.toLowerCase ()).includes ('type:or') ? 'any' : 'all'
navigate (`/posts?${
(new URLSearchParams ({
tags: parts.map (t => t.toLowerCase ())
.filter (t => t !== 'type:or')
.join (' '),
match }))
.toString () }`)
setSuggestionsVsbl (false) setSuggestionsVsbl (false)
} }
} }
const handleTagSelect = (tag: Tag) => { const handleTagSelect = (tag: Tag) => {
const parts = search.split (' ') const parts = search.split (' ')
parts[parts.length - 1] = ( parts[parts.length - 1] = tag.name
(parts[parts.length - 1].slice(0, 4).toLowerCase () === 'not:')
? ('not:' + tag.name)
: tag.name)
setSearch (parts.join (' ') + ' ') setSearch (parts.join (' ') + ' ')
setSuggestions ([]) setSuggestions ([])
setActiveIndex (-1) setActiveIndex (-1)
@@ -96,8 +82,7 @@ export default (() => {
useEffect (() => { useEffect (() => {
const query = new URLSearchParams (location.search) const query = new URLSearchParams (location.search)
const anyFlg = query.get ('match') === 'any' const tagsQuery = query.get ('tags') ?? ''
const tagsQuery = `${ query.get ('tags') ?? '' }${ anyFlg ? ' type:or' : '' }`
setSearch (tagsQuery) setSearch (tagsQuery)
}, [location.search]) }, [location.search])