Commit da14197d authored by Tristan Cavelier's avatar Tristan Cavelier

Js, html and rst updated according to queries

parent 60ff4878
......@@ -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: convertStringToRegExp],
searchTextToRegExp: [Function: searchTextToRegExp],
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
......@@ -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": {
......@@ -352,5 +348,3 @@ Below you can find schemas for constructing queries.
RIGHT_PARENTHESE -> /\)/
ignore: " "
......@@ -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
});
......@@ -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">{&quot;type&quot;:&quot;complex&quot;,&quot;operator&quot;:&quot;AND&quot;,&quot;query_list&quot;:[{&quot;type&quot;:&quot;simple&quot;,&quot;operator&quot;:&quot;=&quot;,&quot;key&quot;:&quot;title&quot;,&quot;value&quot;:&quot;abc&quot;},{&quot;type&quot;:&quot;simple&quot;,&quot;operator&quot;:&quot;=&quot;,&quot;key&quot;:&quot;format&quot;,&quot;value&quot;:&quot;def&quot;}]}</textarea></td>
<td>Query (Object):<br /><textarea id="obj">{&quot;type&quot;:&quot;complex&quot;,&quot;operator&quot;:&quot;AND&quot;,&quot;query_list&quot;:[{&quot;type&quot;:&quot;simple&quot;,&quot;key&quot;:&quot;title&quot;,&quot;value&quot;:&quot;abc&quot;},{&quot;type&quot;:&quot;simple&quot;,&quot;key&quot;:&quot;format&quot;,&quot;value&quot;:&quot;def&quot;}]}</textarea></td>
</tr>
<tr>
<td>Item list (to filter, from 'Query (Object)'):<br /><textarea id="list">[{&quot;title&quot;:&quot;abc&quot;,&quot;format&quot;:&quot;def&quot;},{&quot;title&quot;:&quot;def&quot;,&quot;format&quot;:&quot;abc&quot;}]</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="[[&quot;title&quot;,&quot;ascending&quot;],[&quot;format&quot;,&quot;descending&quot;]]" /></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"))
......
......@@ -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) {
......
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