abinazebinoy commited on
Commit
48f3ef2
·
1 Parent(s): 6de77e6

fix(H-08): replace substring audit name match with relationship-based + word-boundary match -- eliminates false positives for common words like 'India', 'National'

Browse files
Files changed (1) hide show
  1. api/routes/risk.py +12 -4
api/routes/risk.py CHANGED
@@ -102,13 +102,21 @@ def get_risk(entity_id: str, driver=Depends(get_db)):
102
  ))
103
  total_score += raw
104
 
 
 
 
105
  audit_rows = session.run(
106
  """
107
- MATCH (a:AuditReport)
108
- WHERE toLower(a.title) CONTAINS toLower($name)
109
- RETURN count(a) AS audit_count
 
 
 
 
 
110
  """,
111
- name=entity_name
112
  ).single()
113
 
114
  audit_count = audit_rows["audit_count"] if audit_rows else 0
 
102
  ))
103
  total_score += raw
104
 
105
+ # H-08 FIX: name substring match causes massive false positives
106
+ # (e.g. "India" matches every CAG report). Use relationship-based
107
+ # matching first; fall back to exact-word name match only.
108
  audit_rows = session.run(
109
  """
110
+ OPTIONAL MATCH (n {id: $id})-[:MENTIONED_IN]->(a1:AuditReport)
111
+ WITH collect(a1) AS direct
112
+ OPTIONAL MATCH (a2:AuditReport)
113
+ WHERE size(direct) = 0
114
+ AND (toLower(a2.title) CONTAINS (' ' + toLower($name) + ' ')
115
+ OR toLower(a2.title) STARTS WITH (toLower($name) + ' ')
116
+ OR toLower(a2.title) ENDS WITH (' ' + toLower($name)))
117
+ RETURN count(direct) + count(a2) AS audit_count
118
  """,
119
+ id=entity_id, name=entity_name
120
  ).single()
121
 
122
  audit_count = audit_rows["audit_count"] if audit_rows else 0