/*
-** $Id: pz2.js,v 1.18 2007-05-18 15:16:18 jakub Exp $
+** $Id: pz2.js,v 1.32 2007-06-04 12:49:21 jakub Exp $
** pz2.js - pazpar2's javascript client library.
*/
__myself.currQuery = null;
//timers
- __myself.statTime = paramArray.stattime || 2000;
+ __myself.statTime = paramArray.stattime || 1000;
__myself.statTimer = null;
__myself.termTime = paramArray.termtime || 1000;
__myself.termTimer = null;
__myself.bytargetTime = paramArray.bytargettime || 1000;
__myself.bytargetTimer = null;
- //useful?
+ // counters for each command and applied delay
__myself.dumpFactor = 500;
__myself.showCounter = 0;
__myself.termCounter = 0;
+ __myself.statCounter = 0;
+ __myself.bytargetCounter = 0;
// active clients, updated by stat and show
// might be an issue since bytarget will poll accordingly
__myself.showCounter = 0;
__myself.termCounter = 0;
+ __myself.bytargetCounter = 0;
+ __myself.statCounter = 0;
if( !__myself.initStatusOK )
return;
//piggyback search
__myself.show(0, num, sort);
if ( __myself.statCallback )
- __myself.statTimer = setTimeout("__myself.stat()", __myself.statTime / 2);
+ __myself.stat();
+ //__myself.statTimer = setTimeout("__myself.stat()", __myself.statTime / 4);
if ( __myself.termlistCallback )
- //__myself.termlist();
- __myself.termTimer = setTimeout("__myself.termlist()", __myself.termTime / 2);
+ __myself.termlist();
+ //__myself.termTimer = setTimeout("__myself.termlist()", __myself.termTime / 4);
if ( __myself.bytargetCallback )
- __myself.bytargetTimer = setTimeout("__myself.bytarget()", __myself.bytargetTime / 2);
+ __myself.bytarget();
+ //__myself.bytargetTimer = setTimeout("__myself.bytarget()", __myself.bytargetTime / 4);
}
else
// if it gets here the http return code was 200 (pz2 errors are 417)
// but the response was invalid, it should never occur
- setTimeout("__myself.search(__myself.currQuery)", 1000);
+ setTimeout("__myself.search(__myself.currQuery)", 500);
}
);
},
"failed": Number( data.getElementsByTagName("failed")[0].childNodes[0].nodeValue ),
"error": Number( data.getElementsByTagName("error")[0].childNodes[0].nodeValue )
};
+
+ __myself.statCounter++;
+ var delay = __myself.statTime + __myself.statCounter * __myself.dumpFactor;
+ if ( activeClients > 0 )
+ __myself.statTimer = setTimeout("__myself.stat()", delay);
+
__myself.statCallback(stat);
- if (activeClients > 0)
- __myself.statTimer = setTimeout("__myself.stat()", __myself.statTime);
}
else
// if it gets here the http return code was 200 (pz2 errors are 417)
// first parse the status data send along with records
// this is strictly bound to the format
var activeClients = Number( data.getElementsByTagName("activeclients")[0].childNodes[0].nodeValue );
+ __myself.activeClients = activeClients;
var show = {
"activeclients": activeClients,
"merged": Number( data.getElementsByTagName("merged")[0].childNodes[0].nodeValue ),
}
else {
var nodeName = hits[i].childNodes[j].nodeName;
- var nodeText = hits[i].childNodes[j].firstChild.nodeValue;
+ var nodeText = 'ERROR'
+ if ( hits[i].childNodes[j].firstChild )
+ nodeText = hits[i].childNodes[j].firstChild.nodeValue;
show.hits[i][nodeName] = nodeText;
}
}
}
}
- __myself.showCallback(show);
__myself.showCounter++;
var delay = __myself.showTime;
if (__myself.showCounter > __myself.showFastCount)
- //delay *= 2;
delay += __myself.showCounter * __myself.dumpFactor;
- if (activeClients > 0)
+ if ( activeClients > 0 )
__myself.showTimer = setTimeout("__myself.show()", delay);
+
+ __myself.showCallback(show);
}
else
// if it gets here the http return code was 200 (pz2 errors are 417)
if ( recordNode = data.getElementsByTagName("record")[0] ) {
// if stylesheet was fetched do not parse the response
if ( __myself.xslDoc ) {
+ record['recid'] = recordNode.getElementsByTagName("recid")[0].firstChild.nodeValue;
record['xmlDoc'] = data;
record['xslDoc'] = __myself.xslDoc;
} else {
}
}
}
+
__myself.recordCallback(record);
}
else
// if it gets here the http return code was 200 (pz2 errors are 417)
// but the response was invalid, it should never occur
- setTimeout("__myself.record(__myself.currRecID)", 1000);
+ setTimeout("__myself.record(__myself.currRecID)", 500);
}
);
},
{ "command": "termlist", "session": __myself.sessionID, "name": __myself.termKeys },
function(data) {
if ( data.getElementsByTagName("termlist") ) {
- var termList = { "activeclients": Number( data.getElementsByTagName("activeclients")[0].childNodes[0].nodeValue ) };
+ var activeClients = Number( data.getElementsByTagName("activeclients")[0].childNodes[0].nodeValue );
+ __myself.activeClients = activeClients;
+ var termList = { "activeclients": activeClients };
var termLists = data.getElementsByTagName("list");
//for each termlist
for (i = 0; i < termLists.length; i++) {
//for each term in the list
for (j = 0; j < terms.length; j++) {
var term = {
- "name": terms[j].getElementsByTagName("name")[0].childNodes[0].nodeValue,
- "freq": terms[j].getElementsByTagName("frequency")[0].childNodes[0].nodeValue
+ "name": (terms[j].getElementsByTagName("name")[0].childNodes.length
+ ? terms[j].getElementsByTagName("name")[0].childNodes[0].nodeValue
+ : 'ERROR'),
+ "freq": terms[j].getElementsByTagName("frequency")[0].childNodes[0].nodeValue || 'ERROR'
};
var termIdNode = terms[j].getElementsByTagName("id");
}
}
- __myself.termlistCallback(termList);
__myself.termCounter++;
- if (termList["activeclients"] > 0)
- __myself.termTimer = setTimeout("__myself.termlist()", (__myself.termTime + __myself.termCounter*__myself.dumpFactor));
+ var delay = __myself.termTime + __myself.termCounter * __myself.dumpFactor;
+ if ( activeClients > 0 )
+ __myself.termTimer = setTimeout("__myself.termlist()", delay);
+
+ __myself.termlistCallback(termList);
}
else
// if it gets here the http return code was 200 (pz2 errors are 417)
}
}
}
- __myself.bytargetCallback(bytarget);
+
+ __myself.bytargetCounter++;
+ var delay = __myself.bytargetTime + __myself.bytargetCounter * __myself.dumpFactor;
if ( __myself.activeClients > 0 )
- __myself.bytargetTimer = setTimeout("__myself.bytarget()", __myself.bytargetTime);
+ __myself.bytargetTimer = setTimeout("__myself.bytarget()", delay);
+
+ __myself.bytargetCallback(bytarget);
}
else
// if it gets here the http return code was 200 (pz2 errors are 417)
var paramArr = new Array();
for ( var key in params ) {
- paramArr.push(key + '=' + escape(params[key]));
+ paramArr.push(key + '=' + encodeURI(params[key]) );
}
if ( paramArr.length )
var context = this;
this.request.open( 'GET', getUrl, true );
+ this.request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
+ //this.request.setRequestHeader('Accept-Charset', 'UTF-8');
this.request.onreadystatechange = function () {
context._handleResponse();
}
{
var ccl = '';
if( this.simpleQuery != '')
- ccl = '"'+this.simpleQuery+'"';
+ ccl = this.simpleQuery;
for(var i = 0; i < this.advTerms.length; i++)
{
if (ccl != '') ccl = ccl + ' and ';