Skip to content

feat(search): mark a document with the stored filters it matches - #1119

Open
ddeboer wants to merge 2 commits into
mainfrom
feat/stored-search-membership
Open

ddeboer wants to merge 2 commits into
mainfrom
feat/stored-search-membership

Conversation

@ddeboer

@ddeboer ddeboer commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

A run can now mark the documents that belong to a named subset of the index, and keep the index whole. One index, one API and one schema then serve any number of subsets, each with correct facet counts.

What changes

  • @lde/cql2 (new): checks a CQL2 JSON filter against the properties it may name and tests records against it. It reads =, in, a_contains, a_overlaps, and and or, over strings, and refuses the rest. It knows nothing of search.
  • @lde/search: a new projection value, from: 'matchedFilters'. A field declared over it gets the value of every stored filter the document matches. compileStoredFilters(schema, filters) checks the filters against the schema and reports every mistake in one error.
  • @lde/search-pipeline: storedFilters on searchStages and searchIndexerPipeline. The filters extend the pipeline version.
  • @lde/search-indexer: STORED_FILTERS_FILE names a JSON file with the filters.
[
  {
    "type": "CreativeWork",
    "value": "https://example.org/selections/pottery",
    "filter": {
      "op": "a_contains",
      "args": [{ "property": "about" }, ["https://example.org/terms/pottery"]]
    }
  }
]
{
  name: 'selections',
  kind: 'reference',
  array: true,
  from: 'matchedFilters',
  ref: { strategy: 'idOnly', typeName: 'Selection' },
  filterable: true,
}

Declared filterable and not facetable, a where clause on the field is no facet’s own, so every facet counts within the subset. ADR 45 has the reasoning and the limits. It takes up the need behind #1024 for subsets known at indexing time.

Measured

Linked Open Limburg, a full local reindex with images built from this branch (19748 works, 2m42s), one stored filter on about:

where Works Largest about bucket
about in [term] 1309 11090, a term counted over the whole index
collection in [subset] 1309 1309, the term itself; then 849, 206, 91

The filter names an authority’s IRI and matches works that point to a publisher’s own term: a reference holds its target’s key before the filter reads it.

To know before merging

  • The measurement above predates build: install the workspace’s dependency versions in the images #1120: its staged image pinned @traqula/* to the workspace’s versions by hand, which the image lockfile step now does itself.
  • @lde/cql2 is not on npm yet, so it needs the manual first publish right after the merge. @lde/search depends on it.
  • cql2-wasm 0.5.6 was tried first. It throws on = against an absent property and accepts an unknown operator as valid, so the evaluator is our own.

- Add @lde/cql2, which checks a CQL2 JSON filter against the properties it may name and tests
  records against it: =, in, a_contains, a_overlaps, and, or, over strings
- Add the projection value matchedFilters: a field declared over it gets the value of every
  stored filter the document matches, tested at the field’s place in the declaration order
- Add compileStoredFilters, which checks stored filters against the schema and refuses, in one
  error, a filter the schema cannot serve
- Pass storedFilters through searchStages and searchIndexerPipeline, and extend the pipeline
  version with them
- Read the filters from the file STORED_FILTERS_FILE names in the search indexer
- Record the decision as ADR 45
@ddeboer
ddeboer force-pushed the feat/stored-search-membership branch from a7bfc95 to 4c6710c Compare November 25, 2026 13:23
@ddeboer
ddeboer marked this pull request as ready for review November 25, 2026 17:57
- Keep compileFilter, Cql2Expression and QueryableLookup as the surface of @lde/cql2
- Leave FilterMatcher out of the surface of @lde/search

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant