Commit 216870e0 authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Sebastien Robin

JIO provides now a resarch method for jio storages.

If the storage does not search into document list by itself,
JIO will limit it anyway.
The storage should use the method researchDone() to tell to JIO that
the document list is already limited (avoid double limiting).
If the storage can not support limiting, it can also use
searchDocumentArray() provided by JIO (and no need to use researchDone()).
parent a882ef32
...@@ -318,6 +318,8 @@ ...@@ -318,6 +318,8 @@
priv.jio.getDocumentList({ priv.jio.getDocumentList({
'sort':{'lastModified':'descending', 'sort':{'lastModified':'descending',
'fileName':'ascending'}, 'fileName':'ascending'},
'limit':{begin:0,end:50},
// 'search':{fileName:'a'},
'maxtries':3, 'maxtries':3,
'callback':function (result) { 'callback':function (result) {
if (result.status === 'done') { if (result.status === 'done') {
......
...@@ -709,6 +709,7 @@ var JIO = ...@@ -709,6 +709,7 @@ var JIO =
priv.res = {'status':'done','message':''}; priv.res = {'status':'done','message':''};
priv.sorted = false; priv.sorted = false;
priv.limited = false; priv.limited = false;
priv.research_done = false;
//// end Private attributes //// end Private attributes
//// Private Methods //// Private Methods
...@@ -771,6 +772,11 @@ var JIO = ...@@ -771,6 +772,11 @@ var JIO =
priv.res.return_value = priv.res.return_value =
that.limitDocumentArray(priv.res.return_value); that.limitDocumentArray(priv.res.return_value);
} }
// check for research
if (!priv.research_done && typeof priv.job.search !== 'undefined') {
priv.res.return_value =
that.searchDocumentArray(priv.res.return_value);
}
}; };
priv.fail_removeDocument = function () { priv.fail_removeDocument = function () {
priv.res.message = 'Unable to removed document.'; priv.res.message = 'Unable to removed document.';
...@@ -964,7 +970,7 @@ var JIO = ...@@ -964,7 +970,7 @@ var JIO =
* Limits the document list. Clones only the document list between * Limits the document list. Clones only the document list between
* begin and end set in limit object in the job. * begin and end set in limit object in the job.
* @method limitDocumentArray * @method limitDocumentArray
* @param {array} documentarray The array we wont to limit * @param {array} documentarray The array we want to limit
* @return {array} The new document list * @return {array} The new document list
*/ */
that.limitDocumentArray = function (documentarray) { that.limitDocumentArray = function (documentarray) {
...@@ -981,6 +987,38 @@ var JIO = ...@@ -981,6 +987,38 @@ var JIO =
priv.limited = true; priv.limited = true;
}; };
/**
* Search the strings inside the document list. Clones the document list
* containing only the matched strings.
* @method searchDocumentArray
* @param {array} documentarray The array we want to search into.
* @return {array} The new document list.
*/
that.searchDocumentArray = function (documentarray) {
var i, k, newdocumentarray = [];
for (i = 0; i < documentarray.length; i += 1) {
for (k in priv.job.search) {
if (typeof documentarray[i][k] === 'undefined') {
continue;
}
if (documentarray[i][k].search(priv.job.search[k]) > -1) {
newdocumentarray.push(documentarray[i]);
break;
}
}
}
that.researchDone();
return newdocumentarray;
};
/**
* Tells to this storage that the research is already done.
* @method researchDone
*/
that.researchDone = function () {
priv.research_done = true;
};
//// end Public Methods //// end Public Methods
return that; return that;
}; };
......
This diff is collapsed.
...@@ -706,6 +706,7 @@ var JIO = ...@@ -706,6 +706,7 @@ var JIO =
priv.res = {'status':'done','message':''}; priv.res = {'status':'done','message':''};
priv.sorted = false; priv.sorted = false;
priv.limited = false; priv.limited = false;
priv.research_done = false;
//// end Private attributes //// end Private attributes
//// Private Methods //// Private Methods
...@@ -768,6 +769,11 @@ var JIO = ...@@ -768,6 +769,11 @@ var JIO =
priv.res.return_value = priv.res.return_value =
that.limitDocumentArray(priv.res.return_value); that.limitDocumentArray(priv.res.return_value);
} }
// check for research
if (!priv.research_done && typeof priv.job.search !== 'undefined') {
priv.res.return_value =
that.searchDocumentArray(priv.res.return_value);
}
}; };
priv.fail_removeDocument = function () { priv.fail_removeDocument = function () {
priv.res.message = 'Unable to removed document.'; priv.res.message = 'Unable to removed document.';
...@@ -961,7 +967,7 @@ var JIO = ...@@ -961,7 +967,7 @@ var JIO =
* Limits the document list. Clones only the document list between * Limits the document list. Clones only the document list between
* begin and end set in limit object in the job. * begin and end set in limit object in the job.
* @method limitDocumentArray * @method limitDocumentArray
* @param {array} documentarray The array we wont to limit * @param {array} documentarray The array we want to limit
* @return {array} The new document list * @return {array} The new document list
*/ */
that.limitDocumentArray = function (documentarray) { that.limitDocumentArray = function (documentarray) {
...@@ -978,6 +984,38 @@ var JIO = ...@@ -978,6 +984,38 @@ var JIO =
priv.limited = true; priv.limited = true;
}; };
/**
* Search the strings inside the document list. Clones the document list
* containing only the matched strings.
* @method searchDocumentArray
* @param {array} documentarray The array we want to search into.
* @return {array} The new document list.
*/
that.searchDocumentArray = function (documentarray) {
var i, k, newdocumentarray = [];
for (i = 0; i < documentarray.length; i += 1) {
for (k in priv.job.search) {
if (typeof documentarray[i][k] === 'undefined') {
continue;
}
if (documentarray[i][k].search(priv.job.search[k]) > -1) {
newdocumentarray.push(documentarray[i]);
break;
}
}
}
that.researchDone();
return newdocumentarray;
};
/**
* Tells to this storage that the research is already done.
* @method researchDone
*/
that.researchDone = function () {
priv.research_done = true;
};
//// end Public Methods //// end Public Methods
return that; return that;
}; };
......
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