feat: 類似度算出バッチ修正,ほか(#228) (#232)

#228

#228

#228

Co-authored-by: miteruzo <miteruzo@naver.com>
Reviewed-on: #232
This commit was merged in pull request #232.
This commit is contained in:
2026-01-22 23:30:08 +09:00
parent 86209dcc84
commit f6de272f55
18 changed files with 553 additions and 76 deletions
@@ -0,0 +1,34 @@
require 'rails_helper'
RSpec.describe 'post_similarity:calc' do
include RakeTaskHelper
it 'calls Similarity::Calc with Post and :tags' do
# 必要最低限のデータ
t1 = Tag.create!(name: "t1")
t2 = Tag.create!(name: "t2")
t3 = Tag.create!(name: "t3")
p1 = Post.create!(url: "https://example.com/1")
p2 = Post.create!(url: "https://example.com/2")
p3 = Post.create!(url: "https://example.com/3")
# kept スコープが絡むなら、PostTag がデフォで kept になる前提
PostTag.create!(post: p1, tag: t1)
PostTag.create!(post: p1, tag: t2)
PostTag.create!(post: p2, tag: t1)
PostTag.create!(post: p2, tag: t3)
PostTag.create!(post: p3, tag: t3)
expect { run_rake_task("post_similarity:calc") }
.to change { PostSimilarity.count }.from(0)
ps = PostSimilarity.find_by!(post_id: p1.id, target_post_id: p2.id)
ps_rev = PostSimilarity.find_by!(post_id: p2.id, target_post_id: p1.id)
expect(ps_rev.cos).to eq(ps.cos)
end
end
@@ -0,0 +1,34 @@
require 'rails_helper'
RSpec.describe 'tag_similarity:calc' do
include RakeTaskHelper
it 'calls Similarity::Calc with Tag and :posts' do
# 必要最低限のデータ
t1 = Tag.create!(name: "t1")
t2 = Tag.create!(name: "t2")
t3 = Tag.create!(name: "t3")
p1 = Post.create!(url: "https://example.com/1")
p2 = Post.create!(url: "https://example.com/2")
p3 = Post.create!(url: "https://example.com/3")
# kept スコープが絡むなら、PostTag がデフォで kept になる前提
PostTag.create!(post: p1, tag: t1)
PostTag.create!(post: p1, tag: t2)
PostTag.create!(post: p2, tag: t1)
PostTag.create!(post: p2, tag: t3)
PostTag.create!(post: p3, tag: t3)
expect { run_rake_task("tag_similarity:calc") }
.to change { TagSimilarity.count }.from(0)
ps = TagSimilarity.find_by!(tag_id: t1.id, target_tag_id: t2.id)
ps_rev = TagSimilarity.find_by!(tag_id: t2.id, target_tag_id: t1.id)
expect(ps_rev.cos).to eq(ps.cos)
end
end