diff --git a/backend/config/settings.py b/backend/config/settings.py index a8b52f2af8..fc3b22591e 100644 --- a/backend/config/settings.py +++ b/backend/config/settings.py @@ -99,6 +99,7 @@ "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.messages", + "django.contrib.postgres", "django.contrib.staticfiles", ] diff --git a/backend/dissemination/search.py b/backend/dissemination/search.py index 17c0881afc..a0a63a4bbe 100644 --- a/backend/dissemination/search.py +++ b/backend/dissemination/search.py @@ -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) + names_match.add(Q(auditor_firm_name__search=name), Q.OR) query.add(names_match, Q.AND) if uei_or_eins: diff --git a/backend/dissemination/test_search.py b/backend/dissemination/test_search.py index 57fc7ef725..013fbaf744 100644 --- a/backend/dissemination/test_search.py +++ b/backend/dissemination/test_search.py @@ -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 @@ -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): """