Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Aurel
jio
Commits
23885d21
Commit
23885d21
authored
Dec 23, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
custom keys: changed folding example with cast_to and wildcard support
parent
c76af5ed
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
13 deletions
+10
-13
src/queries/core/simplequery.js
src/queries/core/simplequery.js
+1
-2
test/queries/keys.tests.js
test/queries/keys.tests.js
+9
-11
No files found.
src/queries/core/simplequery.js
View file @
23885d21
...
@@ -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
];
}
}
...
...
test/queries/keys.tests.js
View file @
23885d21
...
@@ -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
:
'
aei
ouc
'
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
'
);
});
});
...
...
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