feat(search): Add API for document-to-opinion citations (opinions-cited-by-recap-document)#7448
Open
montenegroleticia wants to merge 11 commits into
Conversation
The serializer no longer exposes the derived cited_opinion_case_name and citing_document_description fields and now lists its fields explicitly, so the viewset doesn't need select_related anymore: the remaining serializer fields are the model's own columns, and the citing_document/cited_opinion hyperlinks are built from the FK ids via DRF's pk-only optimization without touching the related objects. only() and ordering_fields both list every current model field explicitly, so a field added to the model in the future won't be fetched or become orderable automatically. Every listed field is backed by an index (pk, the depth index, the FK indexes and the unique_together index). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Replace the RelatedFilters on OpinionsCitedByRECAPDocumentFilter with plain ModelChoiceFilters. RelatedFilter exposed the full RECAPDocumentFilter/OpinionFilter under the citing_document__ and cited_opinion__ prefixes, allowing arbitrary traversal filtering like ?citing_document__is_available=True. With exact-only filters, such params are now rejected as unknown with an HTTP 400. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Drop assertions on the removed cited_opinion_case_name and citing_document_description serializer fields, assert the citing_document hyperlink instead, refresh the stale N+1 test docstring, and add a regression test confirming related-field traversal filters (e.g. citing_document__is_available) return 400. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
f2d1d3f to
dc28754
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Part of #7354 step 1 of 4, make the API. CourtListener already exposes the opinion-to-opinion citation network via
/api/rest/v4/opinions-cited/, but there's no equivalent for the document <-> opinion citation network stored inOpinionsCitedByRECAPDocument, so API clients can't build a "table of authorities" for a RECAP document or find which documents cite a given opinion.This PR adds a new v4 endpoint,
/api/rest/v4/opinions-cited-by-recap-document/, mirroring/api/rest/v4/opinions-cited/in structure and conventions:OpinionsCitedByRECAPDocumentSerializer: same base classes asOpinionsCitedSerializer(RetrieveFilteredFieldsMixin,DynamicFieldsMixin,HyperlinkedModelSerializerWithId), plus two read-only denormalized fields,cited_opinion_case_nameandciting_document_description, so both directions ("table of authorities" / "who cites this opinion") return everything needed in one page, without a follow-up request per row.OpinionsCitedByRECAPDocumentFilter: exact-match filters onciting_document/cited_opinion(both indexed FKs),depthwith integer lookups, andRelatedFilters intoRECAPDocumentFilter/OpinionFilter.OpinionsCitedByRECAPDocumentViewSet: same mixin stack and permissions asOpinionsCitedViewSet(LoggingMixin,NoFilterCacheListMixin,DeferredFieldsMixin,DjangoModelPermissions+V3APIPermission), cursor pagination ordered by-id.ordering_fieldsis restricted to("id", "depth"): DRF'sOrderingFiltercan't sort on the dottedsourcepaths behind the two denormalized fields.OpinionsCitedByRECAPDocumentFactoryadded tocl/search/factories.pyand wired intomake_dev_datafor local testing.cl/api/tests.pycovering both filter directions,depthfiltering, and the denormalized fields, plustest_list_does_not_n_plus_one, which captures query counts for 1 vs. 2 result rows (each pointing at a distinctcited_opinion/cluster/citing_document) and asserts they're equal, confirmingselect_related("cited_opinion__cluster", "citing_document")resolves the two denormalized fields without growing the query count per row.Known trade-off: the
cited_opinionfilter direction (fan-in on heavily-cited opinions,ORDER BY id) isn't covered by a single index today, same gap exists on the referenceopinions-citedendpoint. Left as a follow-up rather than a speculative migration on a multi-million-row table.Deployment
This PR should:
skip-deploy(skips everything below)skip-web-deployskip-celery-deployskip-cronjob-deployskip-daemon-deployNo special deploy steps required.