From a00c7056c643177c69b8f4f6169c25022b5f559b Mon Sep 17 00:00:00 2001 From: Preetwinder <preet.batth@nexedi.com> Date: Wed, 20 Sep 2017 11:06:25 +0200 Subject: [PATCH] Change regex to case insensitive --- src/queries/query.js | 2 +- test/queries/key.tests.js | 3 ++- test/queries/tests.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/queries/query.js b/src/queries/query.js index a607a41..59465ca 100644 --- a/src/queries/query.js +++ b/src/queries/query.js @@ -416,7 +416,7 @@ } return new RegExp("^" + stringEscapeRegexpCharacters(string) .replace(regexp_percent, '[\\s\\S]*') - .replace(regexp_underscore, '.') + "$"); + .replace(regexp_underscore, '.') + "$", "i"); } /** diff --git a/test/queries/key.tests.js b/test/queries/key.tests.js index afcb8fd..7d06f02 100644 --- a/test/queries/key.tests.js +++ b/test/queries/key.tests.js @@ -601,7 +601,8 @@ then(function (dl) { deepEqual(dl, [ {'identifier': 'à éîöùç'}, - {'identifier': 'âèî ôùc'} + {'identifier': 'âèî ôùc'}, + {'identifier': 'ÀÉÎÖÙÇ'} ], 'It should be possible to query regardless of accents'); }) ); diff --git a/test/queries/tests.js b/test/queries/tests.js index 19d17de..c2adc31 100644 --- a/test/queries/tests.js +++ b/test/queries/tests.js @@ -475,6 +475,36 @@ }); }); + test('Case insensitive queries', function () { + var doc_list = [ + {"identifier": "a", "value": "Test Post", "time": "2016"}, + {"identifier": "b", "value": "test post", "time": "2017"}, + {"identifier": "c", "value": "test3", "time": "2018"} + ]; + stop(); + expect(2); + jIO.QueryFactory.create('test post').exec(doc_list). + then(function (doc_list) { + deepEqual(doc_list, [ + {"identifier": "a", "value": "Test Post", "time": "2016"}, + {"identifier": "b", "value": "test post", "time": "2017"} + ], 'Documunts with the value irrespective of case are matched'); + + doc_list = [ + {"identifier": "a", "value": "Test Post", "time": "2016"}, + {"identifier": "b", "value": "test post", "time": "2017"}, + {"identifier": "c", "value": "test3", "time": "2018"} + ]; + + return jIO.QueryFactory.create('value:"test post"').exec(doc_list). + then(function (doc_list) { + deepEqual(doc_list, [ + {"identifier": "b", "value": "test post", "time": "2017"} + ], 'If value is in quotes, only match if exactly same'); + }).always(start); + }); + }); + // Asterisk wildcard is not supported yet. /* test('Full text query with asterisk', function () { var doc_list = [ -- 2.30.9