Skip to content

ADR 0007: M2 inbox search

Reviewers could filter the inbox by status, town, and type but could not find a capture by the values they have in hand: map/lot, address, owner, or permit number. Captures store the submitted envelope in captures.payload; the matched parcel is in parcels. Unmatched captures have no parcel row, so a search that only queried parcels would hide the most actionable work.

Search is one optional q parameter on the list endpoint

Section titled “Search is one optional q parameter on the list endpoint”

GET /v1/captures accepts q alongside the existing status, townId, type, limit, and cursor parameters. Terms are trimmed, capped at 200 characters, and treated as absent when blank. All filters combine with AND, and cursor pagination continues over the filtered set.

A separate search endpoint was rejected because the authorization, filters, result shape, and pagination are identical; a second route would duplicate them.

Search covers submitted and matched values

Section titled “Search covers submitted and matched values”

The D1 query lowercases and LIKEs the term across:

  • captures.payload → $.parcel.mapLot
  • captures.payload → $.parcel.address
  • captures.payload → $.permit.number
  • joined parcels.map_lot
  • joined parcels.address
  • joined parcels.owner_name

Each value is coalesced to an empty string so absent payload keys or parcels do not exclude rows. The submitted and matched sets overlap after resolution; the duplication keeps unmatched captures searchable.

User input escapes \, %, and _, and every comparison uses ESCAPE '\'. A literal % therefore searches for a percent sign instead of matching every row.

List items expose the submitted parcel and permit number

Section titled “List items expose the submitted parcel and permit number”

captureListItemSchema gains submittedParcel: { mapLot, address | null } and permitNumber: string | null, both derived from the payload. The inbox shows the submitted map/lot and address for unmatched captures, marked unmatched, plus a Permit column. A search result can therefore be confirmed without opening the capture, and matched parcels still take precedence when present.

The web search box is debounced and shared

Section titled “The web search box is debounced and shared”

The inbox search input is debounced by 300 ms before entering the TanStack Query keys. Both grouped requests use the same term, so the Needs Attention and Other captures tables stay independently fetched and filtered. A clear action resets the term. Search is not persisted in the URL.

The scan is acceptable at current tenant volumes. A generated search column or FTS index needs a migration and backfill; revisit when capture volume or query latency makes the scan measurable.

  • Reviewers can locate captures by property, owner, or permit in one step.
  • Search stays server-side and tenant-scoped; the browser never filters another tenant’s data or downloads the full queue.
  • Substring matching is broad by design; type, permit, town, parcel, and status provide disambiguation.
  • Ranking, fuzzy matching, multi-term syntax, saved searches, and URL state remain future work.
  • Inbox paging controls are still deferred.