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

4432 Fixed phrase search queries with § #4877

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion cl/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def cleanup_main_query(query_string: str) -> str:
cleaned_items = []
# Replace smart quotes with standard double quotes for consistency.
query_string = re.sub(r"[“”]", '"', query_string)
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

Expand Down
59 changes: 58 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,43 @@ def test_raise_forbidden_error_on_depth_pagination(self) -> None:
)
self.assertEqual(r.status_code, HTTPStatus.FORBIDDEN)

async def test_avoid_splitting_terms_with_section_mark(self) -> None:
"""Can we avoid splitting words in queries such as §247 and phrases
like "§247"?
"""

# A search for phrase "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())

# A search for phrase "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("34-2535", r.content.decode())

# 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())

# 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("34-2535", 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": ["§ => ALPHANUM"],
"split_on_numerics": False,
"preserve_original": True,
},
Expand Down
Loading