From adf676efbb37e85409686a5d20d48bbfbe128c98 Mon Sep 17 00:00:00 2001 From: Alberto Islas Date: Tue, 26 Nov 2024 16:58:58 -0600 Subject: [PATCH] fix(elasticsearch): Avoid wrapping numbers in quotes in boost queries - Removed Solr failing tests. Fixes: #4737 --- cl/lib/utils.py | 2 +- cl/search/tests/tests.py | 73 ++++++++-------------------------------- 2 files changed, 15 insertions(+), 60 deletions(-) diff --git a/cl/lib/utils.py b/cl/lib/utils.py index 223056420f..592f8876d0 100644 --- a/cl/lib/utils.py +++ b/cl/lib/utils.py @@ -248,7 +248,7 @@ def cleanup_main_query(query_string: str) -> str: """ inside_a_phrase = False cleaned_items = [] - for item in re.split(r'([^a-zA-Z0-9_\-~":]+)', query_string): + for item in re.split(r'([^a-zA-Z0-9_\-^~":]+)', query_string): if not item: continue diff --git a/cl/search/tests/tests.py b/cl/search/tests/tests.py index fe59be528d..3dac875f01 100644 --- a/cl/search/tests/tests.py +++ b/cl/search/tests/tests.py @@ -1076,6 +1076,20 @@ def test_round_estimated_search_counts(self) -> None: with self.subTest(test=test, msg="Test estimated search counts."): self.assertEqual(simplify_estimated_count(test[0]), test[1]) + def test_avoid_wrapping_boosted_numbers_in_quotes(self) -> None: + """Confirm that numbers in boost queries are not wrapped in quotes + that makes the query to fail. + """ + search_params = { + "type": SEARCH_TYPES.ORAL_ARGUMENT, + "q": "Jose^3", + } + r = self.client.get( + reverse("show_results"), + search_params, + ) + self.assertNotIn("encountered an error", r.content.decode()) + class SearchAPIV4CommonTest(ESIndexTestCase, TestCase): """Common tests for the Search API V4 endpoints.""" @@ -1643,35 +1657,6 @@ def test_search_query_saving(self) -> None: "Repeated query not marked as having hit cache", ) - # Force Solr use - @override_flag("oa-es-active", False) - @override_flag("r-es-active", False) - @override_flag("p-es-active", False) - @override_flag("o-es-active", False) - def test_search_query_saving_solr(self) -> None: - """Are queries saved when using solr search (do_search)""" - for query in self.searches: - url = f"{reverse('show_results')}?{query}" - self.client.get(url) - last_query = SearchQuery.objects.last() - expected_query = self.normalize_query(query, replace_space=True) - stored_query = self.normalize_query(last_query.get_params) - self.assertEqual( - expected_query, - stored_query, - f"Query was not saved properly. Expected {expected_query}, got {stored_query}", - ) - self.assertEqual( - last_query.engine, - SearchQuery.SOLR, - f"Saved wrong `engine` value, expected {SearchQuery.SOLR}", - ) - self.assertEqual( - last_query.source, - SearchQuery.WEBSITE, - self.source_error_message, - ) - def test_failed_es_search_queries(self) -> None: """Do we flag failed ElasticSearch queries properly?""" query = "type=r&q=contains/sproximity token" @@ -1772,36 +1757,6 @@ def test_failed_es_search_v3_api_queries(self) -> None: f"Saved wrong `engine` value, expected {SearchQuery.ELASTICSEARCH}", ) - @override_flag("oa-es-active", False) - @override_flag("oa-es-activate", False) - @override_flag("r-es-search-api-active", False) - @override_flag("p-es-active", False) - @override_flag("o-es-search-api-active", False) - def test_search_solr_api_v3_query_saving(self) -> None: - """Do we save queries on all V3 Search Solr endpoints""" - for query in self.base_searches: - url = f"{reverse("search-list", kwargs={"version": "v3"})}?{query}" - self.client.get(url) - # Compare parsed query strings; - last_query = SearchQuery.objects.last() - expected_query = self.normalize_query(query, replace_space=True) - stored_query = self.normalize_query(last_query.get_params) - self.assertEqual( - expected_query, - stored_query, - f"Query was not saved properly. Expected {expected_query}, got {stored_query}", - ) - self.assertEqual( - last_query.engine, - SearchQuery.SOLR, - f"Saved wrong `engine` value, expected {SearchQuery.ELASTICSEARCH}", - ) - self.assertEqual( - last_query.source, - SearchQuery.API, - self.source_error_message, - ) - class CaptionTest(TestCase): """Can we make good looking captions?"""