Skip to content

Commit

Permalink
Merge branch 'main' into 558-implement-es-relevance-decay
Browse files Browse the repository at this point in the history
  • Loading branch information
albertisfu authored Dec 30, 2024
2 parents b40a747 + cb012e8 commit c1e2acd
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 3 deletions.
15 changes: 15 additions & 0 deletions cl/lib/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,16 +1157,31 @@ def test_check_and_sanitize_queries_bad_syntax(self) -> None:
"output": True,
"sanitized": "This is unbalanced",
},
{
"input_str": "This is “unbalanced",
"output": True,
"sanitized": "This is unbalanced",
},
{
"input_str": 'This is "unbalanced""',
"output": True,
"sanitized": 'This is "unbalanced"',
},
{
"input_str": "This is “unbalanced””",
"output": True,
"sanitized": 'This is "unbalanced"',
},
{
"input_str": 'This "is" unbalanced"',
"output": True,
"sanitized": 'This "is" unbalanced',
},
{
"input_str": 'This "is” unbalanced"',
"output": True,
"sanitized": 'This "is" unbalanced',
},
{
"input_str": 'This "is" unbalanced"""',
"output": True,
Expand Down
8 changes: 6 additions & 2 deletions cl/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ def cleanup_main_query(query_string: str) -> str:
"""
inside_a_phrase = False
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):
if not item:
continue
Expand Down Expand Up @@ -330,8 +332,8 @@ def check_unbalanced_quotes(query: str) -> bool:
:param query: The input query string
:return: True if the query contains unbalanced quotes. Otherwise False
"""
quotes_count = query.count('"')
return quotes_count % 2 != 0
all_quotes = re.findall(r"[“”\"]", query)
return len(all_quotes) % 2 != 0


def remove_last_symbol_occurrence(
Expand Down Expand Up @@ -382,6 +384,8 @@ def sanitize_unbalanced_quotes(query: str) -> str:
:param query: The input query string
:return: The sanitized query string, after removing unbalanced quotes.
"""
# Replace smart quotes with standard double quotes for consistency.
query = re.sub(r"[“”]", '"', query)
quotes_count = query.count('"')
while quotes_count % 2 != 0:
query, quotes_count = remove_last_symbol_occurrence(
Expand Down
9 changes: 8 additions & 1 deletion cl/opinion_page/templates/includes/authorities_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
<ul>
{% for authority in authorities %}
<li>
{{ authority.depth }} reference{{ authority.depth|pluralize }} to
{% if docket %}
<a href="/?type=r&q=docket_id%3A{{ docket.pk }}%20AND%20cites%3A({{ authority.cited_opinion.cluster.sub_opinions.all|OR_join }})">
{% endif %}
{{ authority.depth }} reference{{ authority.depth|pluralize }}
{% if docket %}
</a>
{% endif %}
to
<a href="{{ authority.cited_opinion.cluster.get_absolute_url }}{% querystring %}" {% if authority.blocked %}rel="nofollow" {% endif %}>
{{ authority.cited_opinion.cluster.caption|safe|v_wrapper }}
</a>
Expand Down
5 changes: 5 additions & 0 deletions cl/scrapers/management/commands/clone_from_cl.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
manage.py clone_from_cl --type people_db.Person --id 4173 --clone-person-positions
manage.py clone_from_cl --type search.Docket --id 5377675 --clone-person-positions
Note: for cloned Opinion Clusters to appear in docket authorities pages, use the
`find_citations_and_parantheticals_for_recap_documents` method in the Django shell.
You can pass all RECAPDocument IDs, for example:
`RECAPDocument.objects.values_list('pk', flat=True)`, or only a subset if needed.
This is still work in progress, some data is not cloned yet.
"""

Expand Down
2 changes: 2 additions & 0 deletions cl/search/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,8 @@ def test_query_cleanup_function(self) -> None:
"12-9238 happy Gilmore",
'docketNumber:"12-9238"~1 happy Gilmore',
),
("“ping tree” leads", '"ping tree" leads'),
('"this is” a “test"', '"this is" a "test"'),
("1chicken NUGGET", '"1chicken" NUGGET'),
(
"We can drive her home with 1headlight",
Expand Down
2 changes: 2 additions & 0 deletions cl/settings/third_party/rest_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"OVERRIDE_THROTTLE_RATES": {
# Throttling down.
# Multiple accounts
"api_1": "1/hour",
"api_2": "1/hour",
"api_account_1": "1/hour",
"api_account_2": "1/hour",
"api_account_3": "1/hour",
Expand Down

0 comments on commit c1e2acd

Please sign in to comment.