Skip to content

Commit

Permalink
feat(search): Add properties to query Authorities to the Docket model
Browse files Browse the repository at this point in the history
  • Loading branch information
ERosendo committed Dec 1, 2023
1 parent e3e059d commit 153f34f
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions cl/search/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,51 @@ def add_recap_source(self):
# Simply add the RECAP value to the other value.
self.source = self.source + self.RECAP

@property
def authority_count(self):
return OpinionsCitedByRECAPDocument.objects.filter(
citing_document__docket_entry__docket_id=self.pk
).count()

@property
def authorities_with_data(self):
"""Returns a queryset of this document's authorities for
eventual injection into a view template.
The returned queryset is sorted by the depth field.
"""
query = (
OpinionsCitedByRECAPDocument.objects.filter(
citing_document__docket_entry__docket_id=self.pk
)
.select_related("cited_opinion__cluster__docket__court")
.prefetch_related(
"cited_opinion__cluster__citations",
Prefetch(
"cited_opinion__cluster__sub_opinions",
queryset=Opinion.objects.only("pk", "cluster_id"),
),
)
.only(
"depth",
"citing_document_id",
"cited_opinion__cluster__slug",
"cited_opinion__cluster__case_name",
"cited_opinion__cluster__case_name_full",
"cited_opinion__cluster__case_name_short",
"cited_opinion__cluster__citation_count",
"cited_opinion__cluster__docket_id",
"cited_opinion__cluster__date_filed",
"cited_opinion__cluster__docket__docket_number",
"cited_opinion__cluster__docket__court_id",
"cited_opinion__cluster__docket__court__citation_string",
"cited_opinion__cluster__docket__court__full_name",
)
.order_by("-depth")
)

return query

def add_idb_source(self):
if self.source == self.DEFAULT:
self.source = self.IDB
Expand Down

0 comments on commit 153f34f

Please sign in to comment.