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: ...@@ -68,8 +68,7 @@ Example:
['last_modified', 'descending'], ['last_modified', 'descending'],
['creation_date', 'descending'] ['creation_date', 'descending']
], ],
select_list: ['title'], select_list: ['title']
wildcard_character: '%'
}; };
// execution // execution
...@@ -93,7 +92,7 @@ for how to use these methods, in and outside jIO. The module provides: ...@@ -93,7 +92,7 @@ for how to use these methods, in and outside jIO. The module provides:
select: [Function: select], select: [Function: select],
sortOn: [Function: sortOn], sortOn: [Function: sortOn],
limit: [Function: limit], limit: [Function: limit],
convertStringToRegExp: [Function: convertStringToRegExp], searchTextToRegExp: [Function: searchTextToRegExp],
QueryFactory: { [Function: QueryFactory] create: [Function] }, QueryFactory: { [Function: QueryFactory] create: [Function] },
Query: [Function: Query], Query: [Function: Query],
SimpleQuery: { SimpleQuery: {
...@@ -161,16 +160,18 @@ are available in the index. ...@@ -161,16 +160,18 @@ are available in the index.
Matching properties Matching properties
^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^
Complex Queries select items which exactly match the value given in the Complex Queries select items which exactly match the value given in the query
query. You can use wildcards ('%' is the default wildcard character), and you but you can also use wildcards (``%``). If you don't want to use a wildcard,
can change the wildcard character in the query options object. If you don't just set the operator to ``=``.
want to use a wildcard, just set the wildcard character to an empty string.
.. code-block:: javascript .. code-block:: javascript
var query = { var option = {
query: 'creator:"* Doe"', query: 'creator:"% Doe"' // use wildcard
wildcard_character: '*' };
var option = {
query: 'creator:="25%"' // don't use wildcard
}; };
...@@ -191,24 +192,22 @@ Example, convert Query object into a human readable string: ...@@ -191,24 +192,22 @@ Example, convert Query object into a human readable string:
.. code-block:: javascript .. code-block:: javascript
var query = complex_queries.QueryFactory. var query = complex_queries.QueryFactory.
create('year: < 2000 OR title: "*a"'), create('year: < 2000 OR title: "%a"'),
option = { option = {
wildcard_character: '*',
limit: [0, 10] limit: [0, 10]
}, },
human_read = { human_read = {
"": "matches ",
"<": "is lower than ", "<": "is lower than ",
"<=": "is lower or equal than ", "<=": "is lower or equal than ",
">": "is greater than ", ">": "is greater than ",
">=": "is greater or equal than ", ">=": "is greater or equal than ",
"=": "matches ", "=": "is equal to ",
"!=": "doesn't match " "!=": "is different than "
}; };
query.onParseStart = function (object, option) { query.onParseStart = function (object, option) {
object.start = "The wildcard character is '" + object.start = "We need only the " +
(option.wildcard_character || "%") +
"' and we need only the " +
option.limit[1] + option.limit[1] +
" elements from the number " + " elements from the number " +
option.limit[0] + ". "; option.limit[0] + ". ";
...@@ -216,16 +215,15 @@ Example, convert Query object into a human readable string: ...@@ -216,16 +215,15 @@ Example, convert Query object into a human readable string:
query.onParseSimpleQuery = function (object, option) { query.onParseSimpleQuery = function (object, option) {
object.parsed = object.parsed.key + object.parsed = object.parsed.key +
" " + human_read[object.parsed.operator] + " " + human_read[object.parsed.operator || ""] +
object.parsed.value; object.parsed.value;
}; };
query.onParseComplexQuery = function (object, option) { query.onParseComplexQuery = function (object, option) {
object.parsed = "I want all document where " + object.parsed = "I want all document where " +
object.parsed.query_list.join(" " + object.parsed.query_list.join(
object.parsed.operator.toLowerCase() + " " + object.parsed.operator.toLowerCase() + " "
" ") + ) + ". ";
". ";
}; };
query.onParseEnd = function (object, option) { query.onParseEnd = function (object, option) {
...@@ -233,10 +231,8 @@ Example, convert Query object into a human readable string: ...@@ -233,10 +231,8 @@ Example, convert Query object into a human readable string:
}; };
console.log(query.parse(option)); console.log(query.parse(option));
// logged: "The wildcard character is '*' and we need // logged: "We need only the 10 elements from the number 0. I want all
// only the 10 elements from the number 0. I want all // document where year is lower than 2000 or title matches %a. Thank you!"
// document where year is lower than 2000 or title
// matches *a. Thank you!"
JSON Schemas and Grammar JSON Schemas and Grammar
...@@ -293,8 +289,8 @@ Below you can find schemas for constructing queries. ...@@ -293,8 +289,8 @@ Below you can find schemas for constructing queries.
}, },
"operator": { "operator": {
"type": "string", "type": "string",
"default": "=", "default": "",
"format": "(>=?|<=?|!?=)", "format": "(>=?|<=?|!?=|)",
"description": "The operator used to compare." "description": "The operator used to compare."
}, },
"id": { "id": {
...@@ -352,5 +348,3 @@ Below you can find schemas for constructing queries. ...@@ -352,5 +348,3 @@ Below you can find schemas for constructing queries.
RIGHT_PARENTHESE -> /\)/ RIGHT_PARENTHESE -> /\)/
ignore: " " ignore: " "
...@@ -17,15 +17,13 @@ Let's start with a simple search: ...@@ -17,15 +17,13 @@ Let's start with a simple search:
} }
Each of the ``.someproperty`` attribute in objects' metadata is compared with Each of the ``.someproperty`` attribute in objects' metadata is compared with
``comparison_value`` through a function defined by the '=' operator. Normally, ``comparison_value`` through a function defined by the '=' operator.
it would be a string match that uses the wildcard_character, if present.
You can provide your own function to be used as '=' operator: You can provide your own function to be used as '=' operator:
.. code-block:: javascript .. code-block:: javascript
var strictEqual = function (object_value, comparison_value, var strictEqual = function (object_value, comparison_value) {
wildcard_character) {
return comparison_value === object_value; return comparison_value === object_value;
}; };
...@@ -38,7 +36,7 @@ You can provide your own function to be used as '=' operator: ...@@ -38,7 +36,7 @@ You can provide your own function to be used as '=' operator:
value: comparison_value 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. or just ignore it, as in this case.
If you need to convert or preprocess the values before comparison, you can provide 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 ...@@ -145,7 +143,7 @@ property, that behaves like the ``compareFunction`` described in
... ...
return { return {
... ...
'cmp': function (b, wildcard_character) { 'cmp': function (b) {
if (a < b) { if (a < b) {
return -1; return -1;
} }
...@@ -161,8 +159,6 @@ property, that behaves like the ``compareFunction`` described in ...@@ -161,8 +159,6 @@ property, that behaves like the ``compareFunction`` described in
cast_to: myType 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``. 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. The ``.cmp()`` property is also used, if present, by the sorting feature of complex queries.
...@@ -280,5 +276,3 @@ A schema can be used: ...@@ -280,5 +276,3 @@ A schema can be used:
application_name: '...', application_name: '...',
key_schema: key_schema key_schema: key_schema
}); });
...@@ -16,16 +16,12 @@ ...@@ -16,16 +16,12 @@
<table> <table>
<tr> <tr>
<td>Query (String):<br /><textarea id="str">title:abc AND format:def</textarea></td> <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>
<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>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> <td>Result list:<br /><textarea id="result"></textarea></td>
</tr> </tr>
<tr>
<td><label for="wildcard">Wildcard char: </label></td>
<td><input type="text" id="wildcard" name="wildcard" value="%" /></td>
</tr>
<tr> <tr>
<td><label for="sort_on">Sort on: </label></td> <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> <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() { ...@@ -77,7 +73,6 @@ function query() {
).exec( ).exec(
list, list,
{ {
"wildcard_character": $('#wildcard').attr('value'),
"sort_on": JSON.parse($("#sort_on").attr("value")), "sort_on": JSON.parse($("#sort_on").attr("value")),
"limit": JSON.parse($("#limit").attr("value")), "limit": JSON.parse($("#limit").attr("value")),
"select_list": JSON.parse($("#select_list").attr("value")) "select_list": JSON.parse($("#select_list").attr("value"))
......
...@@ -321,8 +321,7 @@ ...@@ -321,8 +321,7 @@
} }
complex_query = gidToComplexQuery(gid); complex_query = gidToComplexQuery(gid);
command.storage(priv.sub_storage).allDocs({ command.storage(priv.sub_storage).allDocs({
"query": complex_query, "query": complex_query
"wildcard_character": null
}).then(function (response) { }).then(function (response) {
var update_method = method; var update_method = method;
response = response.data; response = response.data;
...@@ -381,8 +380,7 @@ ...@@ -381,8 +380,7 @@
} }
complex_query = gidToComplexQuery(gid_object); complex_query = gidToComplexQuery(gid_object);
command.storage(priv.sub_storage).allDocs({ command.storage(priv.sub_storage).allDocs({
"query": complex_query, "query": complex_query
"wildcard_character": null
}).then(function (response) { }).then(function (response) {
response = response.data; response = response.data;
if (response.total_rows === 0) { if (response.total_rows === 0) {
...@@ -459,7 +457,6 @@ ...@@ -459,7 +457,6 @@
complex_query = gidToComplexQuery(gid_object); complex_query = gidToComplexQuery(gid_object);
command.storage(priv.sub_storage).allDocs({ command.storage(priv.sub_storage).allDocs({
"query": complex_query, "query": complex_query,
"wildcard_character": null,
"include_docs": true "include_docs": true
}).then(function (response) { }).then(function (response) {
response = response.data; response = response.data;
...@@ -507,8 +504,7 @@ ...@@ -507,8 +504,7 @@
} }
complex_query = gidToComplexQuery(gid_object); complex_query = gidToComplexQuery(gid_object);
command.storage(priv.sub_storage).allDocs({ command.storage(priv.sub_storage).allDocs({
"query": complex_query, "query": complex_query
"wildcard_character": null
}).then(function (response) { }).then(function (response) {
response = response.data; response = response.data;
if (response.total_rows === 0) { 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