Commit 23885d21 authored by Marco Mariani's avatar Marco Mariani

custom keys: changed folding example with cast_to and wildcard support

parent c76af5ed
...@@ -124,7 +124,6 @@ SimpleQuery.prototype.match = function (item, wildcard_character) { ...@@ -124,7 +124,6 @@ SimpleQuery.prototype.match = function (item, wildcard_character) {
checkKey(key); checkKey(key);
object_value = item[key.read_from]; object_value = item[key.read_from];
// default_match overrides the default '=' operator
default_match = key.default_match; default_match = key.default_match;
// default_match can be a string // default_match can be a string
...@@ -136,7 +135,7 @@ SimpleQuery.prototype.match = function (item, wildcard_character) { ...@@ -136,7 +135,7 @@ SimpleQuery.prototype.match = function (item, wildcard_character) {
// default_match overrides the default '=' operator // default_match overrides the default '=' operator
matchMethod = (default_match || matchMethod); matchMethod = (default_match || matchMethod);
// but an explicit operator: key overrides default_match // but an explicit operator: parameter overrides default_match
if (this._spec && this._spec.operator) { if (this._spec && this._spec.operator) {
matchMethod = this[this.operator]; matchMethod = this[this.operator];
} }
......
...@@ -437,7 +437,6 @@ ...@@ -437,7 +437,6 @@
// https://github.com/walling/unorm/ // https://github.com/walling/unorm/
var accentFold = function (s) { var accentFold = function (s) {
var map = [ var map = [
[new RegExp('\\s', 'gi'), ''],
[new RegExp('[àáâãäå]', 'gi'), 'a'], [new RegExp('[àáâãäå]', 'gi'), 'a'],
[new RegExp('æ', 'gi'), 'ae'], [new RegExp('æ', 'gi'), 'ae'],
[new RegExp('ç', 'gi'), 'c'], [new RegExp('ç', 'gi'), 'c'],
...@@ -447,8 +446,7 @@ ...@@ -447,8 +446,7 @@
[new RegExp('[òóôõö]', 'gi'), 'o'], [new RegExp('[òóôõö]', 'gi'), 'o'],
[new RegExp('œ', 'gi'), 'oe'], [new RegExp('œ', 'gi'), 'oe'],
[new RegExp('[ùúûü]', 'gi'), 'u'], [new RegExp('[ùúûü]', 'gi'), 'u'],
[new RegExp('[ýÿ]', 'gi'), 'y'], [new RegExp('[ýÿ]', 'gi'), 'y']
[new RegExp('\\W', 'gi'), '']
]; ];
map.forEach(function (o) { map.forEach(function (o) {
...@@ -466,24 +464,23 @@ ...@@ -466,24 +464,23 @@
test('Accent folding', function () { test('Accent folding', function () {
equal(accentFold('àéîöùç'), 'aeiouc'); equal(accentFold('àéîöùç'), 'aeiouc');
equal(accentFold('ÀÉÎÖÙÇ'), 'AEIOUC'); equal(accentFold('ÀÉÎÖÙÇ'), 'AEIOUC');
equal(accentFold('àéî öùç'), 'aei ouc');
}); });
test('Query with accent folding (exact matching)', function () { test('Query with accent folding and wildcard', function () {
/*jslint unparam: true*/ /*jslint unparam: true*/
var doc_list, docList = function () { var doc_list, docList = function () {
return [ return [
{'identifier': 'àéîöùç'}, {'identifier': 'àéîöùç'},
{'identifier': 'âèî ôùc'},
{'identifier': 'ÀÉÎÖÙÇ'}, {'identifier': 'ÀÉÎÖÙÇ'},
{'identifier': 'b'} {'identifier': 'b'}
]; ];
}, keys = { }, keys = {
identifier: { identifier: {
read_from: 'identifier', read_from: 'identifier',
default_match: function (object_value, value, wildcard_character) { cast_to: accentFold
// XXX todo: regexp & support wildcard_character
return accentFold(object_value) === accentFold(value);
}
} }
}; };
/*jslint unparam: false*/ /*jslint unparam: false*/
...@@ -492,11 +489,12 @@ ...@@ -492,11 +489,12 @@
complex_queries.QueryFactory.create({ complex_queries.QueryFactory.create({
type: 'simple', type: 'simple',
key: keys.identifier, key: keys.identifier,
value: 'aeiouc' value: 'aei%'
}).exec(doc_list); }).exec(doc_list);
deepEqual(doc_list, [ deepEqual(doc_list, [
{'identifier': 'àéîöùç'} {'identifier': 'àéîöùç'},
], 'It should be possible to query for an exact match regardless of accents'); {'identifier': 'âèî ôùc'}
], 'It should be possible to query regardless of accents');
}); });
......
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