Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 6 additions & 5 deletions efile_app/efile/services/filing_code_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ def filter_filing_groups(

def filing_groups(index, query, initial, courts=()):
fingerprint = hashlib.sha256(f"{index.pk}:{index.refreshed_at}:{initial}:{query}:{courts}".encode()).hexdigest()
key = f"filing-groups-v7:{fingerprint}"
key = f"filing-groups-v8:{fingerprint}"
cached = cache.get(key)
if cached is not None:
return cached
Expand All @@ -936,7 +936,8 @@ def filing_groups(index, query, initial, courts=()):
)
groups = {}
for label in labels:
name = label["filing_type__name"]
# SQLite's JSON key lookup decodes numeric-looking names, such as Illinois' "97" case type.
name = str(label["filing_type__name"])
group_key = filing_group_key(name, index.jurisdiction)
group = groups.setdefault(
group_key, {"key": group_key, "variants": [], "path_count": 0, "rank": 0, "name_rank": 0, "_labels": []}
Expand All @@ -947,8 +948,8 @@ def filing_groups(index, query, initial, courts=()):
"path_count": label["path_count"],
"rank": label["rank"],
"name_rank": label["name_rank"],
"category": label["case_category__name"],
"case_type": label["case_type__name"],
"category": str(label["case_category__name"]),
"case_type": str(label["case_type__name"]),
}
)
group["variants"].append(name)
Expand Down Expand Up @@ -1137,7 +1138,7 @@ def search_grouped_paths(
.distinct()
)
return {
"courts": [{"code": row["court__code"], "name": row["court__name"]} for row in courts],
"courts": [{"code": str(row["court__code"]), "name": str(row["court__name"])} for row in courts],
"corrected_terms": corrected,
}

Expand Down
13 changes: 13 additions & 0 deletions efile_app/efile/tests/test_filing_code_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,19 @@ def test_grouped_endpoint_keeps_court_selection_separate(signed_in, index):
assert signed_in.get(URL, params).status_code == 409


def test_numeric_code_names_stay_text_in_grouped_search(catalog):
# Illinois has a case type named "97"; SQLite's JSON key lookup decodes it as a number.
catalog.types.return_value = [option("97", "97")]
catalog.courts.return_value = [option("42", "42")]
refresh_index("massachusetts")
result = search_grouped_paths(current_index("massachusetts"), "complaint", initial=True)
assert [group["name"] for group in result["groups"]] == ["Summary Process Complaint"]
courts = search_grouped_paths(
current_index("massachusetts"), "complaint", initial=True, group_key=result["groups"][0]["key"]
)["courts"]
assert courts == [{"code": "42", "name": "42"}]


def test_refresh_resumes_completed_courts_after_late_failure(catalog, tmp_path):
def fail_district(court, category, initial):
if court == "district":
Expand Down
Loading