diff --git a/pkg/ofac/mapper_business_test.go b/pkg/ofac/mapper_business_test.go index 418ac309..05b09cd0 100644 --- a/pkg/ofac/mapper_business_test.go +++ b/pkg/ofac/mapper_business_test.go @@ -98,6 +98,20 @@ func TestMapperBusiness__FromSource(t *testing.T) { require.Equal(t, expectedContact, found.Contact) }) + t.Run("44525", func(t *testing.T) { + found := ofactest.FindEntity(t, "44525") + require.Equal(t, "BEL-KAP-STEEL LLC", found.Name) + + t.Logf("%#v", found.Business) + + expectedGovernmentIDs := []search.GovernmentID{ + {Type: "tax-id", Country: "United States", Identifier: "52-2083095"}, + {Type: "business-registration", Country: "Connecticut", Identifier: "0582030"}, + {Type: "business-registration", Country: "Florida", Identifier: "M99000000961"}, + } + require.ElementsMatch(t, expectedGovernmentIDs, found.Business.GovernmentIDs) + }) + t.Run("50544", func(t *testing.T) { found := ofactest.FindEntity(t, "50544") diff --git a/pkg/search/similarity_exact.go b/pkg/search/similarity_exact.go index 2daa3e93..6d1c3227 100644 --- a/pkg/search/similarity_exact.go +++ b/pkg/search/similarity_exact.go @@ -38,6 +38,10 @@ func compareExactIdentifiers[Q any, I any](w io.Writer, query Entity[Q], index E } } +func normalizeIdentifier(id string) string { + return strings.ReplaceAll(id, "-", "") +} + // comparePersonExactIDs checks exact matches for Person-specific identifiers func comparePersonExactIDs(w io.Writer, query *Person, index *Person, weight float64) scorePiece { if query == nil || index == nil { @@ -57,7 +61,7 @@ func comparePersonExactIDs(w io.Writer, query *Person, index *Person, weight flo for _, iID := range index.GovernmentIDs { if strings.EqualFold(string(qID.Type), string(iID.Type)) && strings.EqualFold(qID.Country, iID.Country) && - strings.EqualFold(qID.Identifier, iID.Identifier) { + strings.EqualFold(normalizeIdentifier(qID.Identifier), normalizeIdentifier(iID.Identifier)) { score += 15.0 hasMatch = true goto GovIDDone // Break both loops on first match @@ -103,7 +107,7 @@ func compareBusinessExactIDs(w io.Writer, query *Business, index *Business, weig // Exact match on all identifier fields if strings.EqualFold(string(qID.Type), string(iID.Type)) && strings.EqualFold(qID.Country, iID.Country) && - strings.EqualFold(qID.Identifier, iID.Identifier) { + strings.EqualFold(normalizeIdentifier(qID.Identifier), normalizeIdentifier(iID.Identifier)) { score += 15.0 hasMatch = true goto IdentifierDone @@ -149,7 +153,7 @@ func compareOrgExactIDs(w io.Writer, query *Organization, index *Organization, w // Exact match on all identifier fields if strings.EqualFold(string(qID.Type), string(iID.Type)) && strings.EqualFold(qID.Country, iID.Country) && - strings.EqualFold(qID.Identifier, iID.Identifier) { + strings.EqualFold(normalizeIdentifier(qID.Identifier), normalizeIdentifier(iID.Identifier)) { score += 15.0 hasMatch = true goto IdentifierDone diff --git a/pkg/search/similarity_exact_test.go b/pkg/search/similarity_exact_test.go new file mode 100644 index 00000000..c89fec1c --- /dev/null +++ b/pkg/search/similarity_exact_test.go @@ -0,0 +1,43 @@ +package search + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestCompareBusinessExactIDs(t *testing.T) { + cases := []struct { + query, index Business + expected scorePiece + }{ + { + query: Business{ + GovernmentIDs: []GovernmentID{ + {Type: GovernmentIDTax, Country: "United States", Identifier: "522083095"}, + }, + }, + index: Business{ + GovernmentIDs: []GovernmentID{ + {Type: GovernmentIDTax, Country: "United States", Identifier: "52-2083095"}, + }, + }, + expected: scorePiece{ + score: 1.0, + weight: 50, + matched: true, + required: true, + exact: true, + fieldsCompared: 1, + pieceType: "identifiers", + }, + }, + } + for _, tc := range cases { + t.Run(fmt.Sprintf("%#v", tc.query.GovernmentIDs), func(t *testing.T) { + got := compareBusinessExactIDs(nil, &tc.query, &tc.index, criticalIdWeight) + require.Equal(t, tc.expected, got) + }) + } +}