Files
huangguo_server/skd/service/contentreviewser/issue_builder.go
T
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

93 lines
2.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package contentreviewser
import (
"fmt"
"strings"
"91porn-server/models/v/contentreviewmod"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// issueBuilder 用 Builder 模式构建 ReviewIssue
// 通过链式调用 MatchXxx 收集各字段的命中,HasHits/Build 在所有匹配后调用
type issueBuilder struct {
issue *contentreviewmod.ReviewIssue
hitSet map[string]struct{}
descLines []string
}
func newIssueBuilder(taskID primitive.ObjectID, targetType contentreviewmod.IssueTargetType, targetID primitive.ObjectID) *issueBuilder {
return &issueBuilder{
issue: &contentreviewmod.ReviewIssue{
TaskID: taskID,
TargetType: targetType,
TargetID: targetID,
},
hitSet: make(map[string]struct{}),
}
}
// WithMediaID 设置关联的 MediaID(仅 ACG_CONTENT 需要)
func (b *issueBuilder) WithMediaID(id primitive.ObjectID) *issueBuilder {
b.issue.MediaID = id
return b
}
// MatchTitle 匹配标题字段;命中时存入高亮版本并累计描述
// label 是描述文案中的字段名(如"标题"、"章节名"
func (b *issueBuilder) MatchTitle(label, text string, terms []string) *issueBuilder {
if hits, hl := matchAndHighlight(text, terms); len(hits) > 0 {
b.issue.Title = hl
b.addHits(label, hits)
}
return b
}
func (b *issueBuilder) MatchContent(label, text string, terms []string) *issueBuilder {
if hits, hl := matchAndHighlight(text, terms); len(hits) > 0 {
b.issue.Content = hl
b.addHits(label, hits)
}
return b
}
func (b *issueBuilder) MatchTags(label, text string, terms []string) *issueBuilder {
if hits, hl := matchAndHighlight(text, terms); len(hits) > 0 {
b.issue.Tags = hl
b.addHits(label, hits)
}
return b
}
func (b *issueBuilder) MatchRichText(label, text string, terms []string) *issueBuilder {
if hits, hl := matchAndHighlight(text, terms); len(hits) > 0 {
b.issue.RichText = hl
b.addHits(label, hits)
}
return b
}
// HasHits 是否至少有一个字段命中
func (b *issueBuilder) HasHits() bool {
return len(b.hitSet) > 0
}
// Build 收尾:拼装 Description 与去重后的 HitWords
func (b *issueBuilder) Build() *contentreviewmod.ReviewIssue {
hits := make([]string, 0, len(b.hitSet))
for h := range b.hitSet {
hits = append(hits, h)
}
b.issue.HitWords = hits
b.issue.Description = strings.Join(b.descLines, "\n")
return b.issue
}
func (b *issueBuilder) addHits(label string, hits []string) {
b.descLines = append(b.descLines, fmt.Sprintf("%s命中 %s", label, strings.Join(hits, "、")))
for _, h := range hits {
b.hitSet[h] = struct{}{}
}
}