Skip to content

Commit a9f026a

Browse files
seapyclaude
andcommitted
fix: 퍼지 검색에서 법인 형태어(주식회사 등) 노이즈 제거
'주식회사 오늘의집' 검색 시 '두성에스비텍주식회사'처럼 법인 형태어 바이그램(주식·식회·회사)만 겹치는 무관한 회사가 반환되는 문제 수정. 퍼지 비교 전에 주식회사·유한회사·합자회사·(주)·(유) 등을 쿼리와 대상 이름 양쪽에서 모두 제거한 뒤 바이그램 유사도를 계산한다. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5d19045 commit a9f026a

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

internal/cache/corpcode.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,16 @@ func (s *Store) fuzzySearch(query string, threshold float64, max int) []*CorpInf
139139
info *CorpInfo
140140
score float64
141141
}
142+
// Strip legal form words from the query once before the loop.
143+
normalizedQuery := stripLegalForm(query)
144+
if normalizedQuery == "" {
145+
return nil
146+
}
147+
142148
var results []scored
143149
for _, info := range s.All {
144-
score := bigramSim(query, strings.ToLower(info.CorpName))
150+
normalizedTarget := stripLegalForm(strings.ToLower(info.CorpName))
151+
score := bigramSim(normalizedQuery, normalizedTarget)
145152
if score >= threshold {
146153
results = append(results, scored{info, score})
147154
}
@@ -159,6 +166,22 @@ func (s *Store) fuzzySearch(query string, threshold float64, max int) []*CorpInf
159166
return out
160167
}
161168

169+
// legalFormReplacer strips common Korean legal entity form words so they don't
170+
// inflate bigram similarity scores (e.g. "주식회사" appears in thousands of names).
171+
var legalFormReplacer = strings.NewReplacer(
172+
"주식회사", "",
173+
"유한회사", "",
174+
"합자회사", "",
175+
"합명회사", "",
176+
"유한책임회사", "",
177+
"(주)", "",
178+
"(유)", "",
179+
)
180+
181+
func stripLegalForm(s string) string {
182+
return strings.TrimSpace(legalFormReplacer.Replace(s))
183+
}
184+
162185
// bigramSim returns the fraction of query's character bigrams that appear in target.
163186
// Uses rune-level bigrams for correct Korean handling.
164187
func bigramSim(query, target string) float64 {

internal/cache/corpcode_test.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ func testStore() *Store {
1717
{CorpCode: "00000002", CorpName: "카카오뱅크"},
1818
{CorpCode: "00000003", CorpName: "카카오페이"},
1919
{CorpCode: "01154811", CorpName: "주식회사 오늘의집"},
20+
// 법인 형태어 노이즈 테스트용: "주식회사"를 포함하는 무관한 회사
21+
{CorpCode: "99999999", CorpName: "두성에스비텍주식회사(구:두성공업주식회사)"},
2022
}
2123
return buildStore(corps)
2224
}
@@ -112,7 +114,7 @@ func TestSearch_Fuzzy_마켓컬리(t *testing.T) {
112114
}
113115

114116
func TestSearch_Fuzzy_오늘의집(t *testing.T) {
115-
// "오늘의집" → substring 으로도 찾힘, fuzzy 로도 찾혀야 함
117+
// "오늘의집" → substring 으로도 찾힘
116118
s := testStore()
117119
results := s.Search("오늘의집")
118120
if len(results) == 0 {
@@ -129,6 +131,34 @@ func TestSearch_Fuzzy_오늘의집(t *testing.T) {
129131
}
130132
}
131133

134+
func TestSearch_Fuzzy_법인형태어_노이즈제거(t *testing.T) {
135+
// "주식회사 오늘의집" 검색 시 "주식회사"를 공유하는 무관한 회사가 나오면 안 됨
136+
s := testStore()
137+
results := s.Search("주식회사 오늘의집")
138+
for _, r := range results {
139+
if r.CorpName == "두성에스비텍주식회사(구:두성공업주식회사)" {
140+
t.Fatalf("'주식회사 오늘의집' 검색에서 무관한 회사 '두성에스비텍주식회사'가 반환됨 (법인 형태어 노이즈)")
141+
}
142+
}
143+
t.Logf("'주식회사 오늘의집' 검색 결과: %v", corpNames(results))
144+
}
145+
146+
func TestStripLegalForm(t *testing.T) {
147+
cases := []struct{ in, want string }{
148+
{"주식회사 오늘의집", "오늘의집"},
149+
{"삼성전자(주)", "삼성전자"},
150+
{"(주)카카오", "카카오"},
151+
{"유한회사테스트", "테스트"},
152+
{"컬리", "컬리"},
153+
}
154+
for _, c := range cases {
155+
got := stripLegalForm(c.in)
156+
if got != c.want {
157+
t.Errorf("stripLegalForm(%q) = %q, want %q", c.in, got, c.want)
158+
}
159+
}
160+
}
161+
132162
func TestSearch_NoResult_완전엉뚱한검색어(t *testing.T) {
133163
s := testStore()
134164
results := s.Search("xyzxyz없는기업명zyx")

0 commit comments

Comments
 (0)