Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search: inexact matches on name fields #2642

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.postgres",
"django.contrib.staticfiles",
]

Expand Down
5 changes: 4 additions & 1 deletion backend/dissemination/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ def search_general(
# TODO: use something like auditee_name__contains
# SELECT * WHERE auditee_name LIKE '%SomeString%'
if names:
names_match = Q(Q(auditee_name__in=names) | Q(auditor_firm_name__in=names))
names_match = Q()
for name in names:
names_match.add(Q(auditee_name__search=name), Q.OR)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we downcase/normalize anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not explicitly, because this (__search) uses psql's full text search, which is case-insensitive by default as far as I can tell (and it does in fact behave as such in our tests)

names_match.add(Q(auditor_firm_name__search=name), Q.OR)
query.add(names_match, Q.AND)

if uei_or_eins:
Expand Down
30 changes: 28 additions & 2 deletions backend/dissemination/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,32 @@ def test_name_multiple(self):
assert_all_results_public(self, results)
self.assertEqual(len(results), 2)

def test_name_matches_inexact(self):
"""
Given a partial name, search_general should return records whose name fields contain the term, even if not an exact match
"""
auditee_match = baker.make(
General, is_public=True, auditee_name="the university of somewhere"
)
auditor_match = baker.make(
General, is_public=True, auditor_firm_name="auditors unite, LLC"
)
baker.make(General, is_public=True, auditee_name="not looking for this auditee")
baker.make(
General,
is_public=True,
auditor_firm_name="not looking for this auditor firm",
)

results = search_general(
names=["UNIVERSITY", "unitE", "there is not match for this one"]
)

assert_all_results_public(self, results)
self.assertEqual(len(results), 2)
self.assertEqual(results[0], auditee_match)
self.assertEqual(results[1], auditor_match)

def test_uei_or_ein_matches_uei(self):
"""
Given a uei_or_ein, search_general should return records with a matching UEI
Expand Down Expand Up @@ -194,13 +220,13 @@ def test_oversight_agency(self):
baker.make(General, is_public=True, oversight_agency="02")

results = search_general(
cog_or_oversight="cog",
cog_or_oversight="oversight",
agency_name="01",
)

assert_all_results_public(self, results)
self.assertEqual(len(results), 1)
self.assertEqual(results[0].cognizant_agency, "01")
self.assertEqual(results[0].oversight_agency, "01")

def test_audit_year(self):
"""
Expand Down