fix: correlate $search ranking ORDER BY to the outer row - #1717
Draft
patricebender wants to merge 4 commits into
Draft
fix: correlate $search ranking ORDER BY to the outer row#1717patricebender wants to merge 4 commits into
patricebender wants to merge 4 commits into
Conversation
The deep-search ranking ORDER BY reused the search expression without binding
it to the outer query row, so the sub-select produced a `key IN (key)`
tautology instead of a correlation (the TODO in cqn4sql). Defer the ranking
ORDER BY to after infer(), where the outer alias is known, and correlate the
score sub-select to the outer row post-transform (mirroring expand's
_correlate). A deep search fans one outer row out to many joined child rows,
so wrap the score in MAX() to keep the scalar sub-select single-valued and
rank by the best-matching child.
Also emit the numeric flag as the proper CQN literal `{ val: true }`, and make
the HANA fuzzy `search` renderer idempotent: it rewrites annotated columns
in place (ref -> xpr), which crashed when the same search() args are rendered
twice (WHERE predicate + injected ranking ORDER BY).
Verified end-to-end against a real HANA: deep to-many $search ranks by best
match, de-duplicated; fuzzy suite green.
The inherited `$self` composition (SearchAuthors : Authors) made the backlink resolve to the base entity, which cds-compiler 7.0.1 (CI) rejects during the relational SQL transform. Make the model self-contained: SearchAuthors owns its books composition and Books.author points to SearchAuthors directly, so the $self backlink is unambiguous. Verified compile+to.sql on 7.0.1 and the e2e ranking still passes on a real HANA.
patricebender
force-pushed
the
feat/hana-search-orderby-ranking-correlation
branch
from
August 27, 2026 15:58
0bd6c4d to
6083a81
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The deep-search ranking ORDER BY reused the search expression without binding it to the outer query row, so the sub-select produced a
key IN (key)tautology instead of a correlation. By defering the rankingORDER BYto afterinfer(), where the outer alias is known, the score sub-select can be correlated to the outer row post-transform (mirroring expand's _correlate). A deep search may lead to one outer row yielding many joined child rows, so wrap the score in MAX() to keep the scalar sub-select single-valued and rank by the best-matching child.