Skip to content

Commit

Permalink
fix(search): Fixed phrase search queries with §
Browse files Browse the repository at this point in the history
Fixes: #4432
  • Loading branch information
albertisfu committed Jan 1, 2025
1 parent f2c464f commit 5684f6a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
33 changes: 32 additions & 1 deletion cl/search/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,27 +422,42 @@ def setUpTestData(cls):
sub_opinions=RelatedFactory(
OpinionWithChildrenFactory,
factory_related_name="cluster",
html_columbia="<p>Code, &#167; 1-815</p>",
html_columbia="<p>Code, &#167; 1-815 Lorem §247</p>",
),
precedential_status=PRECEDENTIAL_STATUS.PUBLISHED,
)
OpinionClusterFactoryWithChildrenAndParents(
case_name="Strickland v. Lorem.",
docket=DocketFactory(court=cls.court, docket_number="123456"),
sub_opinions=RelatedFactory(
OpinionWithChildrenFactory,
factory_related_name="cluster",
plain_text="Random plain_text",
),
precedential_status=PRECEDENTIAL_STATUS.PUBLISHED,
)
OpinionClusterFactoryWithChildrenAndParents(
case_name="America vs Bank",
docket=DocketFactory(
court=cls.child_court_1, docket_number="34-2535"
),
sub_opinions=RelatedFactory(
OpinionWithChildrenFactory,
factory_related_name="cluster",
plain_text="Lorem 247",
),
precedential_status=PRECEDENTIAL_STATUS.PUBLISHED,
)
OpinionClusterFactoryWithChildrenAndParents(
case_name="Johnson v. National",
docket=DocketFactory(
court=cls.child_court_2_2, docket_number="36-2000"
),
sub_opinions=RelatedFactory(
OpinionWithChildrenFactory,
factory_related_name="cluster",
plain_text="Random plain_text",
),
precedential_status=PRECEDENTIAL_STATUS.PUBLISHED,
)

Expand All @@ -451,6 +466,11 @@ def setUpTestData(cls):
docket=DocketFactory(
court=cls.child_gand_2, docket_number="38-1000"
),
sub_opinions=RelatedFactory(
OpinionWithChildrenFactory,
factory_related_name="cluster",
plain_text="Random plain_text",
),
precedential_status=PRECEDENTIAL_STATUS.PUBLISHED,
)
call_command(
Expand Down Expand Up @@ -838,6 +858,17 @@ def test_raise_forbidden_error_on_depth_pagination(self) -> None:
)
self.assertEqual(r.status_code, HTTPStatus.FORBIDDEN)

async def test_avoid_splitting_terms_on_phrase_queries(self) -> None:
"""Can we avoid splitting words in phrase queries such as "§247"?"""

# A search for "Lorem §247" shouldn't match "Lorem 247"
r = await self.async_client.get(
reverse("show_results"), {"q": '"Lorem §247"'}
)
actual = self.get_article_count(r)
self.assertEqual(actual, 1)
self.assertIn("1:21-cv-1234", r.content.decode())


class SearchAPIV4CommonTest(ESIndexTestCase, TestCase):
"""Common tests for the Search API V4 endpoints."""
Expand Down
1 change: 1 addition & 0 deletions cl/settings/third_party/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
"filter": {
"custom_word_delimiter_filter": {
"type": "word_delimiter",
"type_table": ["§ => ALPHA"],
"split_on_numerics": False,
"preserve_original": True,
},
Expand Down

0 comments on commit 5684f6a

Please sign in to comment.