Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio-main
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
Hardik Juneja
jio-main
Commits
3c383627
Commit
3c383627
authored
Jul 17, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
complex_queries.js updated
parent
032cc5bc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
14 deletions
+81
-14
complex_queries.js
complex_queries.js
+81
-14
No files found.
complex_queries.js
View file @
3c383627
...
...
@@ -741,6 +741,33 @@ function stringEscapeRegexpCharacters(string) {
_export
(
"
stringEscapeRegexpCharacters
"
,
stringEscapeRegexpCharacters
);
/**
* Convert metadata values to array of strings. ex:
*
* "a" -> ["a"],
* {"content": "a"} -> ["a"]
*
* @param {Any} value The metadata value
* @return {Array} The value in string array format
*/
function
metadataValueToStringArray
(
value
)
{
var
i
,
new_value
=
[];
if
(
value
===
undefined
)
{
return
undefined
;
}
if
(
!
Array
.
isArray
(
value
))
{
value
=
[
value
];
}
for
(
i
=
0
;
i
<
value
.
length
;
i
+=
1
)
{
if
(
typeof
value
[
i
]
===
'
object
'
)
{
new_value
[
i
]
=
value
[
i
].
content
;
}
else
{
new_value
[
i
]
=
value
[
i
];
}
}
return
new_value
;
}
/**
* A sort function to sort items by key
*
...
...
@@ -751,12 +778,50 @@ _export("stringEscapeRegexpCharacters", stringEscapeRegexpCharacters);
function
sortFunction
(
key
,
way
)
{
if
(
way
===
'
descending
'
)
{
return
function
(
a
,
b
)
{
return
a
[
key
]
<
b
[
key
]
?
1
:
a
[
key
]
>
b
[
key
]
?
-
1
:
0
;
// this comparison is 5 times faster than json comparison
var
i
,
l
;
a
=
metadataValueToStringArray
(
a
[
key
])
||
[];
b
=
metadataValueToStringArray
(
b
[
key
])
||
[];
l
=
a
.
length
>
b
.
length
?
a
.
length
:
b
.
length
;
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
if
(
a
[
i
]
===
undefined
)
{
return
1
;
}
if
(
b
[
i
]
===
undefined
)
{
return
-
1
;
}
if
(
a
[
i
]
>
b
[
i
])
{
return
-
1
;
}
if
(
a
[
i
]
<
b
[
i
])
{
return
1
;
}
}
return
0
;
};
}
if
(
way
===
'
ascending
'
)
{
return
function
(
a
,
b
)
{
return
a
[
key
]
>
b
[
key
]
?
1
:
a
[
key
]
<
b
[
key
]
?
-
1
:
0
;
// this comparison is 5 times faster than json comparison
var
i
,
l
;
a
=
metadataValueToStringArray
(
a
[
key
])
||
[];
b
=
metadataValueToStringArray
(
b
[
key
])
||
[];
l
=
a
.
length
>
b
.
length
?
a
.
length
:
b
.
length
;
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
if
(
a
[
i
]
===
undefined
)
{
return
-
1
;
}
if
(
b
[
i
]
===
undefined
)
{
return
1
;
}
if
(
a
[
i
]
>
b
[
i
])
{
return
1
;
}
if
(
a
[
i
]
<
b
[
i
])
{
return
-
1
;
}
}
return
0
;
};
}
throw
new
TypeError
(
"
complex_queries.sortFunction():
"
+
...
...
@@ -1250,17 +1315,18 @@ SimpleQuery.prototype["="] = function (object_value, comparison_value,
if
(
comparison_value
===
undefined
)
{
if
(
value
===
undefined
)
{
return
true
;
}
else
{
return
false
;
}
return
false
;
}
if
(
value
===
undefined
)
{
return
false
;
}
if
(
convertStringToRegExp
(
comparison_value
.
toString
(),
wildcard_character
).
test
(
value
.
toString
()))
{
if
(
convertStringToRegExp
(
comparison_value
.
toString
(),
wildcard_character
).
test
(
value
.
toString
())
)
{
return
true
;
}
}
...
...
@@ -1290,17 +1356,18 @@ SimpleQuery.prototype["!="] = function (object_value, comparison_value,
if
(
comparison_value
===
undefined
)
{
if
(
value
===
undefined
)
{
return
false
;
}
else
{
return
true
;
}
return
true
;
}
if
(
value
===
undefined
)
{
return
true
;
}
if
(
convertStringToRegExp
(
comparison_value
.
toString
(),
wildcard_character
).
test
(
value
.
toString
()))
{
if
(
convertStringToRegExp
(
comparison_value
.
toString
(),
wildcard_character
).
test
(
value
.
toString
())
)
{
return
false
;
}
}
...
...
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