Aller au contenu principal

search

Status: implemented (services/search, contract: docs/dev/phase4-contracts.md, Search service; specs: features.md "Search", frontend.md search bar rules). Runs in the apps profile of docker-compose.yml on port 8093 (metrics 9193, :9090 in compose) and is reached through the gateway route /v1/search.

Role: backend of the main search bar. It keeps one OpenSearch document per readable resource, rebuilt from the owning service on every domain event, and answers typo-tolerant queries filtered by the caller's permissions.

Limits: documents hold only what a result needs (title, subtitle, keywords, short descriptions, site, project, ACL fields). Narrowed search bars of the modules (inventory, members…) keep using their own list endpoints.

Flow​

Indexed types​

typeSource (Kafka topic → REST)Title / subtitleWeb route
membermembers.member.v1 → /v1/members/directory?ids=display name only/app/members/<id>
iteminventory.item.v1 → /v1/inventory/items/<id>name / short code, category, brand model/app/inventory/<id>
locationinventory.location.v1 → /v1/inventory/locations/<id>name / ancestors path/app/inventory?site=&location=<id>
eventevents.event.v1 → /v1/events/<id>title / place/app/events/<id>
projectprojects.project.v1 → /v1/projects/<id>name / description/app/projects/<id>
sheetborrowing.sheet.v1 → /v1/borrowing/sheets/<id>member borrower (empty for external borrowers) / purpose/app/borrowing/<id>
customer, supplierfinance.customer.v1, finance.supplier.v1name / account code; individuals: account code only/app/finance/customers/<id>, /suppliers/<id>
quote, invoicefinance.quote.v1, finance.invoice.v1number (or subject for drafts) / subject/app/finance/quotes/<id>, /invoices/<id>
purchasefinance.purchase.v1title/app/finance/purchases/<id>

No private PII is indexed: members only by display name (the directory card, no private field is ever fetched), external borrowers never by name, finance individuals only by their pseudonymous account code. Busy (redacted) event views and deleted resources are never indexed.

Indexing​

  • Consumer (group search-indexer): every event of the topics above makes the indexer fetch the current resource with the service principal (PRINCIPAL_SIGNING_KEY) and upsert the document, or delete it when the service answers 404 / 410 or the resource is deleted. The aggregate ID is the CloudEvent subject (else data.id, data.<type>_id). Unknown event types and payload fields are ignored; malformed events are dropped.
  • Versioning: writes use OpenSearch external versioning (external_gte, version = event time in milliseconds), so replays and out-of-order deliveries never overwrite newer data. Delete tombstones are kept one hour (gc_deletes).
  • Erasure: members.member.erased deletes the member document and removes the ID from every ACL field (creator_id, borrower_id, invitee_ids, member_ids).
  • Backfill / reindex: a lease job (search-reindex, checked every REINDEX_CHECK_INTERVAL) runs pending jobs: it pages through each list endpoint, upserts every document, then deletes the documents of the type not written since the run started (resources deleted while the consumer was behind). A new index requests a backfill automatically; POST /v1/search/reindex (settings.organization.update, audited search.index.reindex) requests one. A type whose service is unreachable is reported in failed_types and kept as is.

Index​

One index (SEARCH_INDEX, default atelier-search) created from an index template:

  • analyzers: folded (standard tokenizer, French elision, lowercase, ASCII folding), french_folded (+ French stop words and light stemming), edge (edge n-grams 2–20, index time only);
  • title is a search_as_you_type field (+ title.fr, title.edge); subtitle, keywords (+ keywords.edge, normalised keywords.exact), body (descriptions, low weight);
  • filter fields: type, id, site_id, project_id, acl.*; sort tie breaker key (<type>:<id>).

Query​

GET /v1/search?q=&types=&limit=&cursor= (see the API reference):

  • q: 2 to 200 characters (whitespace collapsed); types: comma list (all by default); limit: default 10, capped at 20; cursor: next_cursor of the previous page (search_after on score + key).
  • Relevance: prefix on the last word (bool_prefix on the search-as-you-type fields), fuzzy match (AUTO edit distance, first letter exact) on titles, subtitles, keywords and descriptions, edge n-grams, and a strong boost for exact codes (A-7K3QZ0MD, F-PAR-2026-0001).
  • Access: one filter per type, combined with OR. The scopes come from authz LookupResources (all, sites, projects, IDs), fetched concurrently once per request (plus SubjectRoles when events are searched).
TypeVisible when
memberany authenticated user; API keys and services: members.member.read scope
item, locationinventory.item.read, inventory.location.read scope
eventpublic; creator; invited user, global role or project role; events.event.update scope (manage_all in admin mode); events.event.read_private scope when the event invites read_private holders
projectprojects.project.read scope (+ read_all in admin mode) or project member
sheetborrowing.sheet.read scope (+ read_all in admin mode), member borrower or creator
customer, supplier, quote, invoicefinance.<type>.read scope
purchasefinance.purchase.read scope or requester

The response keeps the shape used by the web client: {items: [{type, id, title, subtitle, url}], next_cursor}. Rate limiting stays in the gateway.

Data​

OpenSearch index (documents) and MongoDB search (jobs reindex state, locks, outbox for audit records).

Environment​

VariableDefaultPurpose
HTTP_ADDR / METRICS_ADDR:8093 / :9193Listeners
OPENSEARCH_URLhttp://localhost:9200OpenSearch nodes (comma-separated)
SEARCH_INDEXatelier-searchIndex and template name
MONGO_URI, MONGO_DATABASEsearchJob state, leases, outbox
AUTHZ_URLlocalhostScopes and roles
MEMBERS_URL, INVENTORY_URL, EVENTS_URL, PROJECTS_URL, BORROWING_URL, FINANCE_URLlocalhost portsResource reads
PRINCIPAL_PUBLIC_KEY, PRINCIPAL_SIGNING_KEYrequiredVerify callers, sign the service principal
REINDEX_CHECK_INTERVAL30sBackfill job period
FETCH_TIMEOUT10sUpstream call timeout

Tests: unit tests with fakes, integration tests with an OpenSearch container (opensearchproject/opensearch:3.9.0, security plugin disabled; OPENSEARCH_TEST_URL reuses a running node), mongotest and kafkatest, all skipped with -short.