Skip to content

Commit

Permalink
Merge branch 'main' into update-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-vogel authored Jan 20, 2025
2 parents c1ac228 + 83b20e5 commit 4942f30
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
13 changes: 10 additions & 3 deletions hana/lib/cql-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,16 @@ const StandardFunctions = {
if (Array.isArray(arg)) arg = [{ val: arg.filter(a => a.val).map(a => a.val).join(' ') }]
else arg = [arg]
const searchTerms = arg[0].val
.match(/("")|("(?:[^"]|\\")*(?:[^\\]|\\\\)")|(\S*)/g)
.filter(el => el.length).map(el => `%${el.replace(/^\"|\"$/g, '').toLowerCase()}%`)

.match(/("")|("(?:[^"]|\\")*(?:[^\\]|\\\\)")|(\S*)/g)
.filter(el => el.length)
.map(el => {
try {
return `%${JSON.parse(el).toLowerCase()}%`
} catch {
return `%${el.toLowerCase()}%`
}
})

const columns = ref.list
const xpr = []
for (const s of searchTerms) {
Expand Down
15 changes: 14 additions & 1 deletion hana/test/fuzzy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('search', () => {
const res = await cqn
expect(res.length).to.be(2) // Eleonora and Jane Eyre
})

test('fallback - 2 search terms', async () => {
const { Books } = cds.entities('sap.capire.bookshop')
const cqn = SELECT.from(Books).search('"autobio"', '"Jane"').columns('1')
Expand All @@ -74,5 +74,18 @@ describe('search', () => {
const res = await cqn
expect(res.length).to.be(1) // Jane Eyre
})

test('fallback - 3 search terms with special characters', async () => {
const { Books } = cds.entities('sap.capire.bookshop')
const cqn = SELECT.from(Books).search('"1847"', '1846', '"\\"Ellis Bell\\""').columns('1')
const { sql, values } = cqn.toSQL()
// 5 columns to be searched createdBy, modifiedBy, title, descr, currency_code
expect(sql.match(/(like)/g).length).to.be(15)
expect(values).to.include('%1847%')
expect(values).to.include('%1846%')
expect(values).to.include('%"ellis bell"%')
const res = await cqn
expect(res.length).to.be(1) // Emily Brontë
})
})
})
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4942f30

Please sign in to comment.