Skip to content

fix(search-typesense): replace what a local lookup stated with the resolved document - #819

Merged
ddeboer merged 2 commits into
mainfrom
worktree-local-lookup-replace
Sep 4, 2026
Merged

fix(search-typesense): replace what a local lookup stated with the resolved document#819
ddeboer merged 2 commits into
mainfrom
worktree-local-lookup-replace

Conversation

@ddeboer

@ddeboer ddeboer commented Sep 4, 2026

Copy link
Copy Markdown
Member

Fix #816

A lookup reference with local: true stores what the referring document states about the referent, and localLookupValue in @lde/search-typesense combined the resolved document with that copy at query time. The combination was a spread over the target type’s physical fields, and a language-keyed text field fans out into several of those. So a name_und the referring document stated survived beside the target’s name_nl, and a resolved reference answered two names where the document it points to answers one. The same gap let any field the target’s record does not carry survive on the reference after the target dropped it.

Change

Once the lookup found the target’s document, return that document instead of merging it over the stored copy. The three cases the contract on ReferenceStrategy.local already describes are now literal:

  • identified and indexed → the target’s own record, carrying what the projection asked for, as a plain lookup does;
  • identified but not indexed → what was stated here, plus the id;
  • not identified → what was stated here, with no id.

The per-logical-field merge from the issue was rejected: it fixes the name but still leaks fields the target lacks.

What stays the same

Nothing changes at index time. The copy is still stored unconditionally, because at extraction the question is is this referent identified, while only at query time is it is that document indexed. The stored shape is unchanged, so no reindex is needed, and the copy remains available should a surface want to show what the referring dataset says about the referent.

The wording of the local contract in @lde/search, the reference docs, ADR 24 and the test comments changes from “overlays” to “replaces”. The test fixture now stores the copy in another language than the target’s record, plus a field that record lacks, so the old spread fails the test.

Follow-up

#818 records the redesign discussed while fixing this: dropping the local flag so every lookup stores the copy, with the _id companion serving facet and join as well as filter.

…solved document

- A resolved local lookup used to spread the target’s record over the
  stored copy, per physical field, so a name stated here in one language
  survived beside the target’s name in another, and a field the target’s
  record lacks survived after the target dropped it
- Return the resolved document instead, so a resolved entry says exactly
  what the projection asked for, as a plain lookup does; the stored copy
  still serves the identified-but-not-indexed and unidentified cases
- Reword the ‘local’ contract and the docs from ‘overlays’ to ‘replaces’
- Widen the test fixture so the stored copy and the target’s record
  disagree per physical field
… stored copy

- Reword the comments in the local lookup tests and ADR 24 that still
  described the overlay
- Use typographer’s apostrophes in the added prose
@ddeboer
ddeboer merged commit 3e4ada8 into main Sep 4, 2026
4 checks passed
@ddeboer
ddeboer deleted the worktree-local-lookup-replace branch September 4, 2026 09:52
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.

search-typesense: a resolved local lookup merges the target’s record with what the referring document stated

1 participant