From d98e4693879e49f0e51721e7b56354b2dd7f9925 Mon Sep 17 00:00:00 2001 From: Eduardo Rosendo Date: Thu, 12 Dec 2024 14:05:32 -0400 Subject: [PATCH 1/2] feat(search): Enhances query_string queries --- cl/lib/elasticsearch_utils.py | 1 + cl/search/tests/tests_es_recap.py | 36 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/cl/lib/elasticsearch_utils.py b/cl/lib/elasticsearch_utils.py index de19b030b5..5d6bb4eb19 100644 --- a/cl/lib/elasticsearch_utils.py +++ b/cl/lib/elasticsearch_utils.py @@ -486,6 +486,7 @@ def build_text_filter(field: str, value: str) -> List: "query": value, "fields": [field], "default_operator": "AND", + "quote_field_suffix": ".exact", } } if "caseName" in field and '"' not in value: diff --git a/cl/search/tests/tests_es_recap.py b/cl/search/tests/tests_es_recap.py index f37c0ade9b..d7eededb87 100644 --- a/cl/search/tests/tests_es_recap.py +++ b/cl/search/tests/tests_es_recap.py @@ -864,6 +864,42 @@ def test_filter_docket_with_no_documents(self) -> None: docket.delete() docket_2.delete() + def test_cause_filter(self) -> None: + """Confirm cause filter works properly""" + # Confirm parties extracted from case_name are available in filters. + with self.captureOnCommitCallbacks(execute=True): + d = DocketFactory( + court=self.court, + docket_number="23-cv-12335", + case_name="Lockhart v. Gainwell Technologies LLC", + cause="31:3730 Qui Tam False Claims Act", + source=Docket.RECAP, + ) + d_2 = DocketFactory( + court=self.court, + docket_number="22-cv-00526", + case_name="Schermerhorn v. Quality Enterprises USA, Inc.", + cause="31:3730 Qui Tam False Claims Act", + source=Docket.RECAP, + ) + + params = { + "type": SEARCH_TYPES.RECAP, + "q": 'cause:"31:3730 Qui Tam False Claims Act"', + } + async_to_sync(self._test_article_count)( + params, 2, "faceted_cause_query_string" + ) + params = { + "type": SEARCH_TYPES.RECAP, + "cause": '"31:3730 Qui Tam False Claims Act"', + } + async_to_sync(self._test_article_count)(params, 2, "cause_filter") + + with self.captureOnCommitCallbacks(execute=True): + d.delete() + d_2.delete() + def test_party_name_filter(self) -> None: """Confirm party_name filter works properly""" From 6686f5f9199e7d680ea06e92a490c64ac20990c4 Mon Sep 17 00:00:00 2001 From: Eduardo Rosendo Date: Thu, 12 Dec 2024 15:14:14 -0400 Subject: [PATCH 2/2] refactor(search): Tweaks test_cause_filter for better readability --- cl/search/tests/tests_es_recap.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cl/search/tests/tests_es_recap.py b/cl/search/tests/tests_es_recap.py index d7eededb87..5351e6c144 100644 --- a/cl/search/tests/tests_es_recap.py +++ b/cl/search/tests/tests_es_recap.py @@ -883,16 +883,19 @@ def test_cause_filter(self) -> None: source=Docket.RECAP, ) + cause_str = "31:3730 Qui Tam False Claims Act" params = { "type": SEARCH_TYPES.RECAP, - "q": 'cause:"31:3730 Qui Tam False Claims Act"', + # Do it in main query box + "q": f'cause:"{cause_str}"', } async_to_sync(self._test_article_count)( params, 2, "faceted_cause_query_string" ) params = { "type": SEARCH_TYPES.RECAP, - "cause": '"31:3730 Qui Tam False Claims Act"', + # Do it in the cause field as a phrase + "cause": f'"{cause_str}"', } async_to_sync(self._test_article_count)(params, 2, "cause_filter")