Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions db-service/lib/cqn4sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ function _cqn4sql(originalQuery, model, useTechnicalAlias = true) {
const { where, having } = transformSearch(searchTerm)
if (where) inferred.SELECT.where = where
else if (having) inferred.SELECT.having = having
if (searchTerm.func) (inferred.SELECT.orderBy ??= []).unshift({ func: searchTerm.func, args: [...searchTerm.args, true], sort: 'desc' })
else if (searchTerm.xpr) {
const searchSelect = searchTerm.xpr[2]
const searchFunc = searchSelect.SELECT.where[0]
; (inferred.SELECT.orderBy ??= []).unshift({
__proto__: SELECT.from(searchSelect.SELECT.from)
.columns({ func: searchFunc.func, args: [...searchFunc.args, true] })
.where([searchTerm.xpr[0], 'in', { list: searchSelect.SELECT.columns }]), // TODO: <-- ensure that the sub select in the order by is bound to the original query result row
Comment thread
patricebender marked this conversation as resolved.
sort: 'desc'
})
}
}
}
// query modifiers can also be defined in from ref leaf infix filter
Expand Down
4 changes: 2 additions & 2 deletions hana/lib/cql-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const StandardFunctions = {
* @param {string} arg - Argument object containing search values
* @returns {string} - SQL statement
*/
search: function (ref, arg) {
search: function (ref, arg, numeric) {
if (cds.env.hana.fuzzy === false) {
// Handle non-fuzzy search
arg = arg.xpr ? arg.xpr : arg
Expand Down Expand Up @@ -207,7 +207,7 @@ const StandardFunctions = {
}
}

return `(CASE WHEN SCORE(${arg} IN ${ref}) > 0 THEN TRUE ELSE FALSE END)`
return numeric ? `SCORE(${arg} IN ${ref})` : `(CASE WHEN SCORE(${arg} IN ${ref}) > 0 THEN TRUE ELSE FALSE END)`
},

// ==============================
Expand Down
Loading