Commit a00c7056 authored by preetwinder's avatar preetwinder

Change regex to case insensitive

parent a14e25f4
...@@ -416,7 +416,7 @@ ...@@ -416,7 +416,7 @@
} }
return new RegExp("^" + stringEscapeRegexpCharacters(string) return new RegExp("^" + stringEscapeRegexpCharacters(string)
.replace(regexp_percent, '[\\s\\S]*') .replace(regexp_percent, '[\\s\\S]*')
.replace(regexp_underscore, '.') + "$"); .replace(regexp_underscore, '.') + "$", "i");
} }
/** /**
......
...@@ -601,7 +601,8 @@ ...@@ -601,7 +601,8 @@
then(function (dl) { then(function (dl) {
deepEqual(dl, [ deepEqual(dl, [
{'identifier': 'àéîöùç'}, {'identifier': 'àéîöùç'},
{'identifier': 'âèî ôùc'} {'identifier': 'âèî ôùc'},
{'identifier': 'ÀÉÎÖÙÇ'}
], 'It should be possible to query regardless of accents'); ], 'It should be possible to query regardless of accents');
}) })
); );
......
...@@ -475,6 +475,36 @@ ...@@ -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. // Asterisk wildcard is not supported yet.
/* test('Full text query with asterisk', function () { /* test('Full text query with asterisk', function () {
var doc_list = [ var doc_list = [
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment