Skip to content

feat: apply search result to orderby clause - #1564

Closed
BobdenOs wants to merge 3 commits into
mainfrom
feat/hana-search-orderby
Closed

BobdenOs wants to merge 3 commits into
mainfrom
feat/hana-search-orderby

Conversation

@BobdenOs

@BobdenOs BobdenOs commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@johannes-vogel johannes-vogel added the next release pr to be checked for next release label Aug 11, 2026
Comment thread db-service/lib/cqn4sql.js
@patricebender
patricebender force-pushed the feat/hana-search-orderby branch from 4b10532 to 9425c1d Compare August 27, 2026 15:58
@johannes-vogel

Copy link
Copy Markdown
Contributor

consumed in #1725

sjvans pushed a commit that referenced this pull request Sep 7, 2026
Ranks `$search` results by fuzzy relevance on HANA, and correctly
correlates the ranking `ORDER BY` to the outer row. Standalone against
`main` (supersedes the stacked PR #1717 / includes #1564's search-order
groundwork).

### What
- **Rank by relevance**: inject `ORDER BY <score> DESC` for `$search`.
Deep (path) search ranks each outer row by its best-matching child via a
correlated `(SELECT MAX(SCORE(...)) ... WHERE innerKey = outerKey)`
sub-select — resolving the earlier `key IN (key)` tautology (correlation
applied post-`infer()`, mirroring expand's `_correlate`).
- **Gated to scoring backends**: only when `cds.db.kind === 'hana'` and
fuzzy is on — sqlite/postgres (no score) get no ranking.
- **Opt-out**: `cds.env.hana.fuzzy.ranked_search = false`; `fuzzy` also
accepts `{ score, ranked_search }`.
- **Order-by precedence**: user ordering → search rank → runtime
implicit key ordering (`implicit: true`).

### Tests
- cqn4sql: rank shape, precedence, opt-out, non-HANA gating.
- HANA e2e (live-verified): deep to-many ranking + dedup; user order-by
precedence; opt-out contrast; OData `$search` via the bookshop service
showing rank beats implicit key ordering; `fuzzy` object config.

---------

Co-authored-by: Bob den Os <bob.den.os@sap.com>
Co-authored-by: D045778 <johannes.vogel@sap.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

next release pr to be checked for next release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants