Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Alain Takoudjou
jio
Commits
749d779e
Commit
749d779e
authored
Dec 23, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
custom keys: accent folding example
parent
aed2d3c3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
1 deletion
+71
-1
test/queries/keys.tests.js
test/queries/keys.tests.js
+71
-1
No files found.
test/queries/keys.tests.js
View file @
749d779e
/*jslint indent: 2, maxlen: 120, nomen: true, vars: true */
/*jslint indent: 2, maxlen: 120, nomen: true, vars: true */
/*global define, exports, require, module, complex_queries, window, test, ok,
/*global define, exports, require, module, complex_queries, window, test, ok,
deepEqual, sinon */
equal,
deepEqual, sinon */
// define([module_name], [dependencies], module);
// define([module_name], [dependencies], module);
(
function
(
dependencies
,
module
)
{
(
function
(
dependencies
,
module
)
{
...
@@ -431,4 +431,74 @@
...
@@ -431,4 +431,74 @@
});
});
// This method is provided as an example.
// A more robust solution to manage diacritics is recommended for production
// environments, with unicode normalization, like (untested):
// https://github.com/walling/unorm/
var
accentFold
=
function
(
s
)
{
var
map
=
[
[
new
RegExp
(
'
\\
s
'
,
'
gi
'
),
''
],
[
new
RegExp
(
'
[àáâãäå]
'
,
'
gi
'
),
'
a
'
],
[
new
RegExp
(
'
æ
'
,
'
gi
'
),
'
ae
'
],
[
new
RegExp
(
'
ç
'
,
'
gi
'
),
'
c
'
],
[
new
RegExp
(
'
[èéêë]
'
,
'
gi
'
),
'
e
'
],
[
new
RegExp
(
'
[ìíîï]
'
,
'
gi
'
),
'
i
'
],
[
new
RegExp
(
'
ñ
'
,
'
gi
'
),
'
n
'
],
[
new
RegExp
(
'
[òóôõö]
'
,
'
gi
'
),
'
o
'
],
[
new
RegExp
(
'
œ
'
,
'
gi
'
),
'
oe
'
],
[
new
RegExp
(
'
[ùúûü]
'
,
'
gi
'
),
'
u
'
],
[
new
RegExp
(
'
[ýÿ]
'
,
'
gi
'
),
'
y
'
],
[
new
RegExp
(
'
\\
W
'
,
'
gi
'
),
''
]
];
map
.
forEach
(
function
(
o
)
{
var
rep
=
function
(
match
)
{
if
(
match
.
toUpperCase
()
===
match
)
{
return
o
[
1
].
toUpperCase
();
}
return
o
[
1
];
};
s
=
s
.
replace
(
o
[
0
],
rep
);
});
return
s
;
};
test
(
'
Accent folding
'
,
function
()
{
equal
(
accentFold
(
'
àéîöùç
'
),
'
aeiouc
'
);
equal
(
accentFold
(
'
ÀÉÎÖÙÇ
'
),
'
AEIOUC
'
);
});
test
(
'
Query with accent folding (exact matching)
'
,
function
()
{
/*jslint unparam: true*/
var
doc_list
,
docList
=
function
()
{
return
[
{
'
identifier
'
:
'
àéîöùç
'
},
{
'
identifier
'
:
'
ÀÉÎÖÙÇ
'
},
{
'
identifier
'
:
'
b
'
}
];
},
keys
=
{
identifier
:
{
readFrom
:
'
identifier
'
,
defaultMatch
:
function
(
object_value
,
value
,
wildcard_character
)
{
// XXX todo: regexp & support wildcard_character
return
accentFold
(
object_value
)
===
accentFold
(
value
);
}
}
};
/*jslint unparam: false*/
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
identifier
,
value
:
'
aeiouc
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
àéîöùç
'
}
],
'
It should be possible to query for an exact match regardless of accents
'
);
});
}));
}));
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment