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
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
Tomáš Peterka
jio
Commits
da14197d
Commit
da14197d
authored
Mar 03, 2014
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Js, html and rst updated according to queries
parent
60ff4878
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
62 deletions
+41
-62
docs/complex_queries.rst
docs/complex_queries.rst
+33
-39
docs/keys.rst
docs/keys.rst
+4
-10
examples/example-queries.html
examples/example-queries.html
+1
-6
src/jio.storage/gidstorage.js
src/jio.storage/gidstorage.js
+3
-7
No files found.
docs/complex_queries.rst
View file @
da14197d
...
...
@@ -68,8 +68,7 @@ Example:
['last_modified', 'descending'],
['creation_date', 'descending']
],
select_list: ['title'],
wildcard_character: '%'
select_list: ['title']
};
// execution
...
...
@@ -93,7 +92,7 @@ for how to use these methods, in and outside jIO. The module provides:
select: [Function: select],
sortOn: [Function: sortOn],
limit: [Function: limit],
convertStringToRegExp: [Function: convertString
ToRegExp],
searchTextToRegExp: [Function: searchText
ToRegExp],
QueryFactory: { [Function: QueryFactory] create: [Function] },
Query: [Function: Query],
SimpleQuery: {
...
...
@@ -161,16 +160,18 @@ are available in the index.
Matching properties
^^^^^^^^^^^^^^^^^^^
Complex Queries select items which exactly match the value given in the
query. You can use wildcards ('%' is the default wildcard character), and you
can change the wildcard character in the query options object. If you don't
want to use a wildcard, just set the wildcard character to an empty string.
Complex Queries select items which exactly match the value given in the query
but you can also use wildcards (``%``). If you don't want to use a wildcard,
just set the operator to ``=``.
.. code-block:: javascript
var query = {
query: 'creator:"* Doe"',
wildcard_character: '*'
var option = {
query: 'creator:"% Doe"' // use wildcard
};
var option = {
query: 'creator:="25%"' // don't use wildcard
};
...
...
@@ -191,24 +192,22 @@ Example, convert Query object into a human readable string:
.. code-block:: javascript
var query = complex_queries.QueryFactory.
create('year: < 2000 OR title: "*
a"'),
create('year: < 2000 OR title: "%
a"'),
option = {
wildcard_character: '*',
limit: [0, 10]
},
human_read = {
"": "matches ",
"<": "is lower than ",
"<=": "is lower or equal than ",
">": "is greater than ",
">=": "is greater or equal than ",
"=": "
matches
",
"!=": "
doesn't match
"
"=": "
is equal to
",
"!=": "
is different than
"
};
query.onParseStart = function (object, option) {
object.start = "The wildcard character is '" +
(option.wildcard_character || "%") +
"' and we need only the " +
object.start = "We need only the " +
option.limit[1] +
" elements from the number " +
option.limit[0] + ". ";
...
...
@@ -216,16 +215,15 @@ Example, convert Query object into a human readable string:
query.onParseSimpleQuery = function (object, option) {
object.parsed = object.parsed.key +
" " + human_read[object.parsed.operator] +
" " + human_read[object.parsed.operator
|| ""
] +
object.parsed.value;
};
query.onParseComplexQuery = function (object, option) {
object.parsed = "I want all document where " +
object.parsed.query_list.join(" " +
object.parsed.operator.toLowerCase() +
" ") +
". ";
object.parsed.query_list.join(
" " + object.parsed.operator.toLowerCase() + " "
) + ". ";
};
query.onParseEnd = function (object, option) {
...
...
@@ -233,10 +231,8 @@ Example, convert Query object into a human readable string:
};
console.log(query.parse(option));
// logged: "The wildcard character is '*' and we need
// only the 10 elements from the number 0. I want all
// document where year is lower than 2000 or title
// matches *a. Thank you!"
// logged: "We need only the 10 elements from the number 0. I want all
// document where year is lower than 2000 or title matches %a. Thank you!"
JSON Schemas and Grammar
...
...
@@ -276,8 +272,8 @@ Below you can find schemas for constructing queries.
}
}
}
* Simple Queries JSON Schema:
.. code-block:: javascript
...
...
@@ -293,8 +289,8 @@ Below you can find schemas for constructing queries.
},
"operator": {
"type": "string",
"default": "
=
",
"format": "(>=?|<=?|!?=)",
"default": "",
"format": "(>=?|<=?|!?=
|
)",
"description": "The operator used to compare."
},
"id": {
...
...
@@ -318,28 +314,28 @@ Below you can find schemas for constructing queries.
: and_expression
| and_expression search_text
| and_expression OR search_text
and_expression
: boolean_expression
| boolean_expression AND and_expression
boolean_expression
: NOT expression
| expression
expression
: ( search_text )
| COLUMN expression
| value
value
: OPERATOR string
| string
string
: WORD
| STRING
terminal:
OR -> /OR[ ]/
AND -> /AND[ ]/
...
...
@@ -350,7 +346,5 @@ Below you can find schemas for constructing queries.
OPERATOR -> /(>=?|<=?|!?=)/
LEFT_PARENTHESE -> /\(/
RIGHT_PARENTHESE -> /\)/
ignore: " "
ignore: " "
docs/keys.rst
View file @
da14197d
...
...
@@ -17,15 +17,13 @@ Let's start with a simple search:
}
Each of the ``.someproperty`` attribute in objects' metadata is compared with
``comparison_value`` through a function defined by the '=' operator. Normally,
it would be a string match that uses the wildcard_character, if present.
``comparison_value`` through a function defined by the '=' operator.
You can provide your own function to be used as '=' operator:
.. code-block:: javascript
var strictEqual = function (object_value, comparison_value,
wildcard_character) {
var strictEqual = function (object_value, comparison_value) {
return comparison_value === object_value;
};
...
...
@@ -38,7 +36,7 @@ You can provide your own function to be used as '=' operator:
value: comparison_value
}
Inside ``equal_match``, you can decide to interpret the
``wildcard_character
``
Inside ``equal_match``, you can decide to interpret the
wildcard character ``%
``
or just ignore it, as in this case.
If you need to convert or preprocess the values before comparison, you can provide
...
...
@@ -145,7 +143,7 @@ property, that behaves like the ``compareFunction`` described in
...
return {
...
'cmp': function (b
, wildcard_character
) {
'cmp': function (b) {
if (a < b) {
return -1;
}
...
...
@@ -161,8 +159,6 @@ property, that behaves like the ``compareFunction`` described in
cast_to: myType
...
``wildcard_character`` is only passed by ``=`` and ``!=`` operators.
If the < or > comparison makes no sense for the objects, the function should return ``undefined``.
The ``.cmp()`` property is also used, if present, by the sorting feature of complex queries.
...
...
@@ -280,5 +276,3 @@ A schema can be used:
application_name: '...',
key_schema: key_schema
});
examples/example-queries.html
View file @
da14197d
...
...
@@ -16,16 +16,12 @@
<table>
<tr>
<td>
Query (String):
<br
/><textarea
id=
"str"
>
title:abc AND format:def
</textarea></td>
<td>
Query (Object):
<br
/><textarea
id=
"obj"
>
{
"
type
"
:
"
complex
"
,
"
operator
"
:
"
AND
"
,
"
query_list
"
:[{
"
type
"
:
"
simple
"
,
"
operator
"
:
"
=
"
,
"
key
"
:
"
title
"
,
"
value
"
:
"
abc
"
},{
"
type
"
:
"
simple
"
,
"
operator
"
:
"
=
"
,
"
key
"
:
"
format
"
,
"
value
"
:
"
def
"
}]}
</textarea></td>
<td>
Query (Object):
<br
/><textarea
id=
"obj"
>
{
"
type
"
:
"
complex
"
,
"
operator
"
:
"
AND
"
,
"
query_list
"
:[{
"
type
"
:
"
simple
"
,
"
key
"
:
"
title
"
,
"
value
"
:
"
abc
"
},{
"
type
"
:
"
simple
"
,
"
key
"
:
"
format
"
,
"
value
"
:
"
def
"
}]}
</textarea></td>
</tr>
<tr>
<td>
Item list (to filter, from 'Query (Object)'):
<br
/><textarea
id=
"list"
>
[{
"
title
"
:
"
abc
"
,
"
format
"
:
"
def
"
},{
"
title
"
:
"
def
"
,
"
format
"
:
"
abc
"
}]
</textarea></td>
<td>
Result list:
<br
/><textarea
id=
"result"
></textarea></td>
</tr>
<tr>
<td><label
for=
"wildcard"
>
Wildcard char:
</label></td>
<td><input
type=
"text"
id=
"wildcard"
name=
"wildcard"
value=
"%"
/></td>
</tr>
<tr>
<td><label
for=
"sort_on"
>
Sort on:
</label></td>
<td><input
type=
"text"
id=
"sort_on"
name=
"sort_on"
value=
"[["title","ascending"],["format","descending"]]"
/></td>
...
...
@@ -77,7 +73,6 @@ function query() {
).
exec
(
list
,
{
"
wildcard_character
"
:
$
(
'
#wildcard
'
).
attr
(
'
value
'
),
"
sort_on
"
:
JSON
.
parse
(
$
(
"
#sort_on
"
).
attr
(
"
value
"
)),
"
limit
"
:
JSON
.
parse
(
$
(
"
#limit
"
).
attr
(
"
value
"
)),
"
select_list
"
:
JSON
.
parse
(
$
(
"
#select_list
"
).
attr
(
"
value
"
))
...
...
src/jio.storage/gidstorage.js
View file @
da14197d
...
...
@@ -321,8 +321,7 @@
}
complex_query
=
gidToComplexQuery
(
gid
);
command
.
storage
(
priv
.
sub_storage
).
allDocs
({
"
query
"
:
complex_query
,
"
wildcard_character
"
:
null
"
query
"
:
complex_query
}).
then
(
function
(
response
)
{
var
update_method
=
method
;
response
=
response
.
data
;
...
...
@@ -381,8 +380,7 @@
}
complex_query
=
gidToComplexQuery
(
gid_object
);
command
.
storage
(
priv
.
sub_storage
).
allDocs
({
"
query
"
:
complex_query
,
"
wildcard_character
"
:
null
"
query
"
:
complex_query
}).
then
(
function
(
response
)
{
response
=
response
.
data
;
if
(
response
.
total_rows
===
0
)
{
...
...
@@ -459,7 +457,6 @@
complex_query
=
gidToComplexQuery
(
gid_object
);
command
.
storage
(
priv
.
sub_storage
).
allDocs
({
"
query
"
:
complex_query
,
"
wildcard_character
"
:
null
,
"
include_docs
"
:
true
}).
then
(
function
(
response
)
{
response
=
response
.
data
;
...
...
@@ -507,8 +504,7 @@
}
complex_query
=
gidToComplexQuery
(
gid_object
);
command
.
storage
(
priv
.
sub_storage
).
allDocs
({
"
query
"
:
complex_query
,
"
wildcard_character
"
:
null
"
query
"
:
complex_query
}).
then
(
function
(
response
)
{
response
=
response
.
data
;
if
(
response
.
total_rows
===
0
)
{
...
...
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