@@ -77,6 +77,7 @@ func (fc *fuzzyCompletions) lookup(e *et.Event, o *dbt.Entity, since time.Time)
7777}
7878
7979func (fc * fuzzyCompletions ) query (e * et.Event , orgent * dbt.Entity ) * dbt.Entity {
80+ exclusive := true
8081 var lei * general.Identifier
8182
8283 if leient := fc .plugin .orgEntityToLEI (e , orgent ); leient != nil {
@@ -115,6 +116,7 @@ func (fc *fuzzyCompletions) query(e *et.Event, orgent *dbt.Entity) *dbt.Entity {
115116 if err := json .Unmarshal ([]byte (resp .Body ), & result ); err != nil || len (result .Data ) == 0 {
116117 return nil
117118 }
119+ exclusive = len (result .Data ) == 1
118120
119121 for _ , d := range result .Data {
120122 if fc .nameMatch (o , d .Attributes .Value ) {
@@ -132,7 +134,7 @@ func (fc *fuzzyCompletions) query(e *et.Event, orgent *dbt.Entity) *dbt.Entity {
132134 }
133135
134136 rec , err := fc .plugin .getLEIRecord (lei )
135- if err != nil || ! fc .locMatch (e , orgent , rec ) {
137+ if err != nil || ( ! exclusive && ! fc .locMatch (e , orgent , rec ) ) {
136138 return nil
137139 }
138140
@@ -156,13 +158,19 @@ func (fc *fuzzyCompletions) nameMatch(o *org.Organization, name string) bool {
156158}
157159
158160func (fc * fuzzyCompletions ) locMatch (e * et.Event , orgent * dbt.Entity , rec * leiRecord ) bool {
159- if edges , err := e .Session .Cache ().OutgoingEdges (orgent , time.Time {}, "legal_address" , "hq_address" , "location" ); err == nil {
161+ legal_addr := rec .Attributes .Entity .LegalAddress
162+ hq_addr := rec .Attributes .Entity .HeadquartersAddress
163+
164+ if edges , err := e .Session .Cache ().OutgoingEdges (orgent ,
165+ time.Time {}, "legal_address" , "hq_address" , "location" ); err == nil {
160166 for _ , edge := range edges {
161167 if a , err := e .Session .Cache ().FindEntityById (edge .ToEntity .ID ); err == nil && a != nil {
162- if loc , ok := a .Asset .(* contact.Location ); ok &&
163- (loc .PostalCode == rec .Attributes .Entity .LegalAddress .PostalCode ||
164- (loc .PostalCode == rec .Attributes .Entity .HeadquartersAddress .PostalCode )) {
165- return true
168+ if loc , ok := a .Asset .(* contact.Location ); ok {
169+ for _ , p := range append ([]leiAddress {legal_addr , hq_addr }, rec .Attributes .Entity .OtherAddresses ... ) {
170+ if loc .PostalCode == p .PostalCode {
171+ return true
172+ }
173+ }
166174 }
167175 }
168176 }
@@ -183,10 +191,12 @@ func (fc *fuzzyCompletions) locMatch(e *et.Event, orgent *dbt.Entity, rec *leiRe
183191 if edges , err := e .Session .Cache ().OutgoingEdges (cr , time.Time {}, "location" ); err == nil {
184192 for _ , edge := range edges {
185193 if a , err := e .Session .Cache ().FindEntityById (edge .ToEntity .ID ); err == nil && a != nil {
186- if loc , ok := a .Asset .(* contact.Location ); ok &&
187- (loc .PostalCode == rec .Attributes .Entity .LegalAddress .PostalCode ||
188- (loc .PostalCode == rec .Attributes .Entity .HeadquartersAddress .PostalCode )) {
189- return true
194+ if loc , ok := a .Asset .(* contact.Location ); ok {
195+ for _ , p := range append ([]leiAddress {legal_addr , hq_addr }, rec .Attributes .Entity .OtherAddresses ... ) {
196+ if loc .PostalCode == p .PostalCode {
197+ return true
198+ }
199+ }
190200 }
191201 }
192202 }
0 commit comments