diff --git a/sci-log-db/src/__tests__/acceptance/basesnippet.controller.acceptance.ts b/sci-log-db/src/__tests__/acceptance/basesnippet.controller.acceptance.ts index 1b11ac59..3466196a 100644 --- a/sci-log-db/src/__tests__/acceptance/basesnippet.controller.acceptance.ts +++ b/sci-log-db/src/__tests__/acceptance/basesnippet.controller.acceptance.ts @@ -32,7 +32,7 @@ describe('Basesnippet', function (this: Suite) { versionable: true, name: 'aSearchableName', description: 'aSearchableDescription', - textcontent: '

aSearchable TextContent

', + textcontent: '

aSearchable TextContent ♥

', }; before('setupApplication', async () => { @@ -218,23 +218,25 @@ describe('Basesnippet', function (this: Suite) { }); }); - it('Search with token should return 200 and matching body.textcontent', async () => { - await client - .get(`/basesnippets/search=aSearchable TextCont`) - .set('Authorization', 'Bearer ' + token) - .set('Content-Type', 'application/json') - .expect(200) - .then( - result => ( - expect(result.body.length).to.be.eql(1), - expect(result.body[0].textcontent).to.be.eql( - '

aSearchable TextContent

', - ) - ), - ) - .catch(err => { - throw err; - }); + ['aSearchable TextCont', '♥'].forEach((t, i) => { + it(`Search with token should return 200 and matching body.textcontent ${i}`, async () => { + await client + .get(`/basesnippets/search=${encodeURIComponent(t)}`) + .set('Authorization', 'Bearer ' + token) + .set('Content-Type', 'application/json') + .expect(200) + .then( + result => ( + expect(result.body.length).to.be.eql(1), + expect(result.body[0].textcontent).to.be.eql( + '

aSearchable TextContent ♥

', + ) + ), + ) + .catch(err => { + throw err; + }); + }); }); it('Search with token should return 200 and matching body.tags', async () => { diff --git a/sci-log-db/src/mixins/basesnippet.repository-mixin.ts b/sci-log-db/src/mixins/basesnippet.repository-mixin.ts index 69629f9c..94518e1e 100644 --- a/sci-log-db/src/mixins/basesnippet.repository-mixin.ts +++ b/sci-log-db/src/mixins/basesnippet.repository-mixin.ts @@ -391,18 +391,11 @@ function FindWithSearchRepositoryMixin< ) { if (!searchText) return; searchText = searchText.trimStart(); - const searchRegex = {regexp: new RegExp(`.*?${searchText}.*?`, 'i')}; + const searchRegex = {regexp: new RegExp(`.*${searchText}.*`, 'i')}; const searchCondition = [ {name: searchRegex}, {description: searchRegex}, - { - textcontent: { - regexp: new RegExp( - `(?<=

)((?!&).)*${searchText}((?!&).)*(?=<\/p>)`, - 'i', - ), - }, - }, + {htmlTextcontent: searchRegex}, ]; additionalConditions.or = searchCondition; }