From c091b3cf15b889f9ddcad44e2cd1ea298330d529 Mon Sep 17 00:00:00 2001 From: Frank Date: Sat, 23 Sep 2023 00:32:11 +0200 Subject: [PATCH 1/2] Update parseQuery.js add handling of textIndex / search for a phrase, which could be wrongly detected as a date --- lib/parseQuery.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/parseQuery.js b/lib/parseQuery.js index bd46281..19c00e5 100644 --- a/lib/parseQuery.js +++ b/lib/parseQuery.js @@ -251,6 +251,8 @@ function parseQuery(query, options = {}) { // eslint-disable-next-line no-param-reassign obj[key] = new RegExp(m[1], m[2]); } + } else if(key === '$search') { // handle special case text search + obj[key] = value; } else if (/^oid:[a-fA-F0-9]{24}$/.test(value)) { // eslint-disable-next-line prefer-destructuring const objId = value.split(':')[1]; From 33c63974860c8eda73e30112c8dde7b0eb6362a3 Mon Sep 17 00:00:00 2001 From: Frank Date: Sat, 23 Sep 2023 09:21:08 +0200 Subject: [PATCH 2/2] add unit test for text search with a date like string --- test/tests.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/tests.js b/test/tests.js index 1d35365..07149cc 100644 --- a/test/tests.js +++ b/test/tests.js @@ -80,6 +80,13 @@ describe('unittests', function () { }; const mergeResult = obj => _.merge({}, defaultResp, obj); + it('text search is parsed correctly from q', function () { + assert.deepEqual( + parseQuery({ q: JSON.stringify({ $text: {$search: '100-10-7' }}) }), + mergeResult({ q: { $text: {$search: '100-10-7' }} }) + ); + }); + it('objectid is parsed correctly from q', function () { assert.deepEqual( parseQuery({ q: JSON.stringify({ fieldName: 'oid:000000000000000000000000' }) }),