Search and notifications
CourtListener helps users find legal content and follow new activity. Search turns a query and filters into results across opinions, RECAP records, oral arguments, people, and related content. Saved searches and docket subscriptions turn that discovery into email, webhook, feed, or real-time updates.
Discovery model
Search is the main path for finding legal content. A user selects a content type and adds terms or filters such as court, date, case name, docket number, judge, citation, or document fields. The result set can appear on the web site, through search APIs, in a feed, or in an export. See Legal search for the search infrastructure.
The query lives in the URL. This makes a result set linkable and gives a saved search a durable definition. The search form also cleans common query syntax and accepts useful date and docket-number forms before the query reaches the search service. The system records search activity for site and API use. Search history remains separate from saved alerts.
Search also supports meaning-based discovery for opinions. This mode uses a vector supplied with the request and is available through the authenticated V4 API when the service is enabled. Keyword and meaning-based searches remain separate query modes in search activity records.
References: cl/…/forms.py• L585-592 cl/…/forms.py• L674-814 cl/…/api_views.py• L520-635 cl/…/api_views.py• L638-695 cl/…/models.py• L3994-4089
Content types
The search experience presents views over related legal records. Each view answers a different discovery question while sharing query controls where they apply.
| Content type | Discovery purpose |
|---|---|
| Opinions | Find written court decisions and their case, court, judge, date, citation, status, and text. Meaning-based search is available for this type. |
| RECAP | Find cases and filings in the RECAP archive. |
| RECAP dockets | Find cases by docket-level information without requiring a filing match. |
| RECAP documents | Find individual filings and their document fields. |
| Oral arguments | Find recorded arguments with case, court, judge, date, and transcript context. |
| People | Find judges and other legal people records. |
| Parentheticals | Find short explanatory passages linked to opinions. |
Keyword search matches query terms and fields. Meaning-based search finds related opinion text from stored opinion representations. Results can include highlights, snippets, related records, scores, and counts that help users judge relevance. Saved search alerts support a smaller set of content types than interactive search, so a search view is not automatically an alert type.
References: cl/…/models.py• L3994-4023 cl/…/forms.py• L60-592 cl/…/api_views.py• L529-585 cl/…/documents.py• L1937-2079
Search result flow
The search flow validates the request, cleans common query forms, selects the content view, applies filters and ordering, and returns a paged result set. Parent records group related child records, such as an opinion cluster with its opinions or a docket with its filings. The same cleaned query can support a feed, export, or saved alert.
This diagram shows how one query becomes several discovery and follow-up paths.
flowchart LR
A[Query and filters] --> B[Validation and cleanup]
B --> C[Content-specific search]
C --> D[Ordered result set]
D --> E[Web result page]
D --> F[API response]
D --> G[Feed or export]
D --> H[Saved search]
H --> I[Alert definition]
The system returns a clear error for invalid syntax, unsafe wildcards, invalid dates, and other requests that cannot produce a reliable result. The older API uses page-based results. The V4 API uses cursor-based results with a stable unique key for each content type, so page boundaries remain stable when scores tie. It returns one extra result internally to decide whether another page exists, then removes that result from the response.
The API presents the same search contract through JSON, browsable responses, and XML. Invalid control characters are removed only when XML cannot represent a result. The affected IDs are recorded for later content repair rather than allowing one bad value to break the full response.
References: cl/…/forms.py• L674-814 cl/…/api_utils.py• L217-369 cl/…/api_utils.py• L372-531 cl/…/api_renderers.py• L15-66 cl/…/api_views.py• L442-483 cl/…/api_views.py• L520-635 cl/…/feeds.py• L299-334
Search index and source model
Search uses indexed views of legal records rather than querying every source record directly. Parent and child records preserve useful relationships while allowing the system to search case-level fields and document-level text together.
Opinion text can have more than one stored version. Each version records its source and extraction method, while one version is marked as the current or official content. This gives downstream discovery a clear text version and provenance. Opinion meaning-based search adds stored text representations to the indexed opinion record. A batch process estimates text size, groups eligible opinions within a token limit, creates the representations, and stores them for later index updates.
Docket content can come from more than one source. Each source defines its court scope, document identity, readiness rules, alert path, and search behavior. Indexing keeps progress separate for each source and document level. This prevents a repair or full rebuild for one source from hiding progress for another. RECAP document retrieval can fetch missing files from PACER with one active request per court and a retry delay. The fetched file then moves through document processing before it becomes ready for search and alerts.
Changes to records and related fields update the searchable view. A new searchable record is matched against saved alerts after its index document is ready. Supported metadata changes can also trigger matching. File and text changes wait for the source-specific content process to make the record ready. A continuous sweep and targeted history-based repair can restore missing or stale index records without changing the alert identity rules. This keeps discovery and notifications tied to the same indexed representation.
This diagram shows how source content becomes searchable and eligible for alert matching.
flowchart LR
A[Legal record or source file] --> B[Content is ready]
B --> C[Parent and child index record]
C --> D[Search results]
C --> E[Saved-search matching]
F[Repair sweep] --> C
G[Opinion text representation] --> C
References: cl/…/models.py• L3283-3665 cl/…/documents.py• L1329-1663 cl/…/tasks.py• L223-337 cl/…/tasks.py• L536-673 cl/…/tasks.py• L1141-1366 cl/…/generate_opinion_embeddings.py• L25-235 cl/…/pacer_bulk_fetch.py• L214-245 cl/…/pacer_bulk_fetch.py• L482-549 cl/…/sweep_indexer.py• L175-229
Saved search alerts
A saved search alert is a named query owned by a user. It stores the query definition, the content type, the delivery rate, and a private key used by links in alert messages. Users create and edit alerts from a result page, profile, API, or other account flow.
Alert creation applies the same core rules across the web form and API:
- The query must be valid and must not match every new record.
- A query that is expected to produce too many results is refused before delivery can overload the system. The API returns the estimated hit count on successful query changes and keeps that count in the error response when it refuses a broad query.
- Delivery can be real time, daily, weekly, monthly, or off.
- Real-time access and alert counts depend on account eligibility and limits. Commercial alert clients use their alert throttle instead of membership limits.
- RECAP alerts can mean new cases only or both new cases and new filings. Other supported search types use their own alert type and do not accept an unrelated RECAP alert type.
The web result page shows the alert form with the current search summary. It gives anonymous users a sign-in or registration path and gives account holders rate, membership, quota, and coverage guidance. A user can edit an existing alert without counting that alert twice against the quota. The API provides owner-scoped create, read, update, and delete operations for search alerts.
References: cl/…/models.py• L3994-4023 cl/…/forms.py• L674-814 cl/…/api_views.py• L626-695
Search alert matching
When indexed content is ready, the alert system tests it against saved queries. This matching step is called percolation: the new content is checked against stored alert rules rather than running every rule as a separate search.
The matching flow keeps the user-facing result useful and safe:
- Select enabled alerts that match the new content.
- Keep the matching parent or child record and any available highlights.
- Ignore a record already delivered for the same alert.
- Send real-time webhook events and eligible real-time email alerts.
- Store other hits for the selected schedule.
- Group related child hits before a scheduled email is sent.
The system uses different repeat keys for an opinion, a RECAP filing, a docket, and a case-only alert. A source-scoped identity prevents documents from different docket sources from sharing an ID. Source-specific settings can enable or pause matching for a source. Updates that add file or text content wait until that content is ready, so users do not receive an alert for an incomplete searchable record.
References: cl/…/documents.py• L79-110 cl/…/documents.py• L546-584 cl/…/documents.py• L1329-1663 cl/…/tasks.py• L213-337 cl/…/tasks.py• L536-673 cl/…/tasks.py• L1524-1552
Scheduled search delivery
Scheduled delivery separates matching from sending. The system stores a snapshot of each accepted hit as a scheduled alert hit, then groups those hits by user, alert, and main legal record when the selected rate runs.
Daily, weekly, and monthly messages show the records found during the relevant time range. Related filings are merged under their case. Opinion and oral-argument hits are grouped under their main record as well. The message includes a link to the full filtered result set. Sent hits are marked as sent and old hit records are removed over time.
Webhooks are independent of email timing. An enabled search-alert webhook can receive a matching event when it is found, while the email for the same alert can wait for its daily, weekly, or monthly schedule. Storage and per-parent limits stop a broad alert from filling the scheduled-hit store.
References: cl/…/tasks.py• L438-523 cl/…/feeds.py• L89-169
Docket subscriptions
A docket subscription follows one known case rather than a free-form query. A user enables it from a docket page, profile, or API. The system then looks for new entries for that docket and sends updates to active subscribers.
The subscription flow checks the user’s docket-alert quota and serializes concurrent changes so two requests cannot create the same subscription or pass the quota check together. Each user has separate subscription state and a private key for safe email actions.
The alert source selects both the meaning of “new” and the message form. RECAP alerts use RECAP entries and documents. Supreme Court alerts use Supreme Court entries and omit placeholder documents. The same source choice also controls webhook behavior.
This diagram shows how one docket change reaches separate user delivery paths.
sequenceDiagram
participant Source as Court or RECAP source
participant Docket as Docket record
participant Worker as Alert worker
participant User as Subscriber
participant Hook as Webhook
Source->>Docket: Add or update docket activity
Docket->>Worker: Identify source and new entries
Worker->>User: Send case update email
Worker->>Hook: Send docket event when enabled
The system protects subscribers from duplicate RECAP activity when more than one recap.email address reports the same docket entry. A user can disable a docket alert from the profile, the docket page, or a private message link. Terminated dockets enter a warning and cleanup cycle instead of remaining active forever.
References: cl/…/models.py• L300-1089 cl/…/documents.py• L1329-1663 cl/…/tasks.py• L640-673
Delivery channels
The system presents the same discovery result through channels with different timing and control models. Email is the main human-readable channel. Webhooks let another system process alert events. Feeds let a caller pull a saved query without waiting for a message.
| Channel | Primary use | User control |
|---|---|---|
| Search result page | Interactive discovery and alert setup | Query and filters in the URL |
| Search API | Programmatic discovery | Search type, filters, pagination, and semantic options where supported |
| Search feed | Pull-based access to opinion or RECAP results | Feed URL and query filters |
| CSV result email | Long-running export for a user | Search query and destination email |
| Email search alert | Human-readable matching results | Alert rate, enable or disable, and unsubscribe link |
| Search-alert webhook | Matching search content for an integrated system | Webhook endpoint and enabled state |
| Docket email | New entries for a subscribed case | Subscription state and unsubscribe link |
| Docket webhook | New entries for an integrated system | Docket subscription and webhook settings |
Search-alert email content includes the matching case or item, highlights or snippets when available, links to the source, and a path to disable the alert. Docket email content is selected by the docket source and can include user notes and tags. Real-time alerts require the account access and quota for that alert type. RECAP coverage depends on new responsive content entering the archive.
See User alerts for the user-facing alert lifecycle and delivery rules. See Legal search for the search and index model.
References: cl/…/api_views.py• L442-483 cl/…/api_views.py• L520-695 cl/…/feeds.py• L89-169 cl/…/tasks.py• L433-523
Change checklist
When these files or sections are changed, remember to consider these:
- Keep search type names aligned across the search form, API result mapping, saved alert validation, source grouping, and scheduled email grouping.
- Keep the stored query usable by both normal search and percolator matching. A query that works only in one path creates a silent alert failure.
- When changing date or docket-number cleanup, check both the visible result query and the saved query used later for alert estimates and matching.
- When changing alert validation, keep the web form and API aligned on match-all rejection, query validity, alert-type rules, frequency estimates, and quota outcomes.
- Keep keyword and semantic query modes aligned between API validation, stored search activity, opinion embeddings, and index updates.
- When changing cursor sorting or unique IDs, preserve the result type’s stable tie-breaker and its parent/child count behavior.
- When changing XML result fields or cleaning, preserve the JSON contract and the path that records bad source IDs for repair.
- When changing opinion text selection, token limits, or embedding batches, keep the stored representation and the indexed opinion fields in step.
- When changing docket source handling, preserve source ownership, identifier namespace, readiness rule, alert path, and sweep coverage together.
- Keep source-specific index progress separate from other sources. A source or parent/child rebuild must not resume from or overwrite another indexing stream.
- Keep missing-document checks and parent routing aligned with each source’s document identity. A repair job that finds the wrong ID can leave search and alerts silently incomplete.
- Keep de-duplication keys aligned with the notification target. A case, filing, opinion, and source-prefixed document do not share the same identity rule.
- When changing alert rates or quotas, update the shared limit check, creation estimate, matching path, and scheduled delivery path together.
- When changing alert email links or private actions, preserve the secret-key contract for unsubscribe, enable, edit, and profile flows.
- When changing search result fields, update the web result, API serializer, feed, alert payload, and email rendering paths that expose those fields.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A saved query is invalid or matches all content | It cannot be indexed or would generate unusable alert traffic | Validate the query and reject invalid or match-all alerts before saving. |
| A query exceeds the supported result rate | The alert can exceed storage or message limits | Estimate recent volume and reject broad queries before creation or query change. |
| The web form and API apply different alert rules | A user can create an alert in one path that fails in the other | Keep shared limit checks and equivalent validation in both paths. |
| A semantic request lacks a supported opinion type or embedding | The API rejects the request instead of returning meaning-based results | Require the semantic flag, an opinion search type, and a valid vector. |
| Opinion embeddings are missing or outside the token limits | Meaning-based results are incomplete or an opinion is skipped | Select eligible main opinions, enforce token limits, and report missing representations. |
| A source file is fetched but not processed into searchable text | Search and alerts omit the document or match incomplete content | Treat file and text readiness as a separate step before indexing and matching. |
| A user sees stale membership or quota guidance | The user may choose a rate that the server refuses | Build the result-page context from the same quota model used by validation. |
| An alert is deleted while a worker writes its hit | A batch can fail or leave stale match state | Re-check existing alerts and clean per-alert Redis hit sets. |
| A source uses an unscoped document identifier | One source can overwrite or suppress another source’s result | Use source-specific identifiers and repeat keys. |
| A source rebuild shares progress with another source or document level | A restart can skip records or repeat a large range | Use source- and document-level progress keys for indexing work. |
| A docket event is processed more than once | Subscribers receive duplicate case messages | Use per-docket enqueue protection and source-specific entry selection. |
| Concurrent requests toggle one user’s docket alert | A quota can be exceeded or duplicate state can be created | Lock the user profile and keep the docket/user uniqueness rule. |
| A user reaches a docket or RECAP alert quota | A new subscription or alert is refused | Share quota rules between web and API paths and serialize docket changes. |
| A scheduled alert hit is stored but not grouped by its parent case | Users receive repeated or fragmented case entries | Group hits by the alert’s main record before sending. |
| A search result contains invalid XML control characters | XML clients receive a failed response or altered content | Clean only the XML fallback and record affected IDs for source repair. |
Key files
| File | Why to read it |
|---|---|
| cl/…/models.py | Defines search types, indexed legal record concepts, opinion content versions, and recorded search modes. |
| cl/…/forms.py | Defines the shared query, date, court, semantic, and filter contract used by web search and APIs. |
| cl/…/documents.py | Shows the searchable parent/child record model, source-scoped IDs, opinion representations, and alert-query preparation. |
| cl/…/api_views.py | Shows the public search interfaces, result-type mapping, authentication boundary, and semantic search path. |
| cl/…/api_utils.py | Shows API execution, counts, result shaping, caching, and cursor paging. |
| cl/…/api_renderers.py | Shows how XML responses remain usable when source text contains invalid control characters. |
| cl/…/feeds.py | Shows how a query becomes a pull-based opinion or RECAP feed. |
| cl/…/tasks.py | Connects indexed records and relevant updates to search alerts, maintains searchable views, and adds opinion representations. |
| cl/…/generate_opinion_embeddings.py | Shows how opinion text is selected and batched for meaning-based search. |
| cl/…/pacer_bulk_fetch.py | Shows how missing RECAP files enter a rate-limited fetch and processing path. |
| cl/…/sweep_indexer.py | Shows the resumable background sweep that repairs missing or stale index records. |
| cl/…/models.py | Defines saved search alerts, docket subscriptions, and scheduled hits. |
| cl/…/forms.py | Defines user-facing alert validation and quota feedback. |
| cl/…/api_serializers.py | Defines API alert ownership, type rules, frequency estimates, broad-query rejection, and quota errors. |
| cl/…/constants.py | Defines membership-level alert quotas used by the alert experience. |
| cl/…/utils.py | Shows query validation, percolation preparation, identity checks, limits, and alert estimates. |
| cl/…/tasks.py | Shows matching, de-duplication, scheduling, email, and webhook handoff. |
| cl/…/cl_send_recap_alerts.py | Shows the RECAP sweep that finds and schedules case and filing updates. |
| cl/…/cl_send_scheduled_alerts.py | Shows how stored hits become scheduled email messages. |
| cl/…/views.py | Shows subscription, unsubscribe, quota, and private-link behavior. |