Commit 852f9e93 authored by Alexandra Rogova's avatar Alexandra Rogova

queries work but VERY SLOW (up to 10 seconds)

parent fb0ce479
......@@ -37,10 +37,7 @@
body.innerHTML = "";
list.appendChild(list_item);
} else {
parser = new DOMParser();
xmlDoc = parser.parseFromString(item.body,"text/xml");
body_text = xmlDoc.getElementsByTagName("description")[0].childNodes[0].nodeValue;
return this.cut_description(body_text, key)
return this.cut_description(item.description, key)
.push(function (result){
if (result === null) body.innerHTML = "";
else body.innerHTML = result.slice(1);
......@@ -63,7 +60,6 @@
result;
regEx = new RegExp('[^.?!]*' + ' ' + key + ' ' + '[^.?!]*[.?!]', 'gm');
result = regEx.exec(body);
console.log("result:");console.log(result);
if (result === null) return null;
else return result[0];
});
......
......@@ -67,62 +67,33 @@
.declareMethod("search", function (key){
var gadget = this;
return gadget.state.model_gadget.allDocs()
.push(function (result){
return gadget.state.result_gadget.clear()
.push(function(){
return gadget.state.model_gadget.allDocs();
})
.push(function (all_attachments){
var i, j, promise_list = [];
for (i=0; i<result.length; i+=1){
for (j=1; j<result[i].data.rows.length; j+=1){
promise_list.push(gadget.state.model_gadget.get(i, result[i].data.rows[j].id));
for (i=0; i<all_attachments.length; i+=1){
for (j=1; j<all_attachments[i].data.rows.length; j+=1){
promise_list.push(gadget.state.model_gadget.get(i, all_attachments[i].data.rows[j].id));
}
}
console.log(promise_list.length);
return RSVP.all(promise_list);
}).push(function(result){
console.log("result :");
console.log(result);
});
/*var options = { query:'title:"% mai %"'};
return gadget.state.model_gadget.search(options)
.push(function(result){
console.log("result : "); console.log(result);
});*/
/*var gadget = this,
options;
options = {
query:'(title:"% '+key+' %") OR (title:"'+ key + ' %") OR (body:"% '+key+' %")'
};
return gadget.state.result_gadget.clear()
.push(function(){
return gadget.state.model_gadget.search(options);
})
.push (function(result){
if (result.data.rows.length === 0){
}).push(function(all_items){
var i,
regEx = new RegExp('((.* '+key+' .*)|('+key+' .*))', 'gi'),
promise_list = [];
for (i=0; i<all_items.length; i+=1){
if (regEx.test(all_items[i].title) || regEx.test(all_items[i].description)) promise_list.push(gadget.state.result_gadget.addItem(all_items[i], key));
}
if (promise_list.length === 0) {
return gadget.state.result_gadget.addItem({
title : "No results found",
link : ""
}, "");
}
var i,
id,
promise_list = [];
for (i = 0; i < result.data.rows.length; i+=1){
id = result.data.rows[i].id;
promise_list.push(gadget.state.model_gadget.get(id));
}
return RSVP.all(promise_list);
})
.push(function(result_list){
var j,
promise_list = [];
for (j = 0; j < result_list.length; j+=1){
promise_list.push(gadget.state.result_gadget.addItem(result_list[j], key));
}
return RSVP.all(promise_list);
});*/
else return RSVP.all(promise_list);
});
})
.onEvent("submit", function(event){
......
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