-/* $Id: search.js,v 1.1 2007-01-05 11:30:13 sondberg Exp $
+/* $Id: search.js,v 1.11 2007-01-10 09:50:57 sondberg Exp $
* ---------------------------------------------------
* Javascript container
*/
var old_session = session_read();
var url_surveillence;
var recstoshow = 15;
-var cur_termlist = "subject";
+var page_window = 5; // Number of pages prior to and after the current page
+var facet_list;
+var cur_facet = 0;
function initialize ()
{
+ facet_list = get_available_facets();
start_session();
session_check();
}
xinitSession.onreadystatechange=session_started;
xinitSession.open("GET", url);
xinitSession.send(null);
-
- //url_surveillence = setInterval(session_check, 200);
}
function ping_session()
}
+function make_pager (hits, offset, max) {
+ var html = '';
+ var off;
+ var start_offset = offset - page_window * max;
+
+ if (start_offset < 0) {
+ start_offset = 0;
+ }
+
+ for (off = start_offset;
+ off < hits && off < (start_offset + 2 * page_window * max);
+ off += max) {
+
+ var class = '';
+
+ if (off < 0)
+ off = 0;
+
+ var p = off / max + 1;
+
+ if ((offset >= off) && (offset < (off + max)))
+ class = ' class="select"';
+
+ html += '<a href="#" ' + class +
+ 'onclick="update_offset(' + off + ')">' + p + '</a>\n';
+ }
+
+ return html;
+}
+
+
+function update_offset (offset) {
+ document.search.startrec.value = offset;
+ update_action('page');
+ check_search();
+ update_history();
+ return false;
+}
+
+
function show_records()
{
if (xshow.readyState != 4)
var start = Number(xml.getElementsByTagName('start')[0].childNodes[0].nodeValue);
var num = Number(xml.getElementsByTagName('num')[0].childNodes[0].nodeValue);
var clients = Number(xml.getElementsByTagName("activeclients")[0].childNodes[0].nodeValue);
- body.innerHTML = '<b>Records : ';
- body.innerHTML += (start + 1) + ' to ' + (start + num) +
- ' of ' + merged + ' (total hits: ' + total + ')</b>';
-
+ body.innerHTML = '<div class="pages">' +
+ make_pager(merged, start, recstoshow) +
+ '</div>';
+
+ body.innerHTML += '<div class="results">Records : ' + (start + 1) +
+ ' to ' + (start + num) + ' of ' + merged +
+ ' (total hits: ' + total + ')</div><br/><br/>';
+
+/*
if (start + num < merged)
body.innerHTML += ' <a href="" ' +
'onclick="document.search.startrec.value=' + (start + recstoshow) +
';check_search(); update_history();return false;">Previous</a>';
body.innerHTML += '<br/>';
+*/
+ body.innerHTML += '<div class="records">';
+
for (i = 0; i < hits.length; i++)
{
- body.innerHTML += '<p>';
- body.innerHTML += (i + start + 1) + ': ';
- var mk = hits[i].getElementsByTagName("title");
- if (mk[0])
- body.innerHTML += mk[0].childNodes[0].nodeValue;
- body.innerHTML += '</p>';
+ var mk = hits[i].getElementsByTagName("md-title");
+ var html = '<a href="#" class="record">';
+ var field = '';
+
+ if (mk[0]) {
+ field = mk[0].childNodes[0].nodeValue;
+ }
+
+ html += field + '</a>';
+ body.innerHTML += html;
}
+
+ body.innerHTML += '</div>';
shown++;
if (clients > 0)
{
}
}
if (!termtimer)
- termtimer = setTimeout(check_termlist, 1000);
+ termtimer = setTimeout(check_termlist, 500);
}
function check_search()
start_search();
}
-function set_termlist(termlist)
-{
- cur_termlist = termlist;
- check_termlist();
- if (termtimer)
- {
- clearTimeout(termtimer);
- termtimer = 0;
- }
-}
-function show_termlistoptions(body)
-{
- var opts = Array(
- Array('subject', 'Subject'),
- Array('author', 'Author')
- );
-
- for (i in opts)
- {
- if (opts[i][0] == cur_termlist)
- body.innerHTML += opts[i][1];
- else
- body.innerHTML += '<a href="" onclick="set_termlist(\'' + opts[i][0] +
- '\'); return false">' + opts[i][1] + '</a>';
- body.innerHTML += ' ';
- }
- body.innerHTML += '<p>';
-}
function show_termlist()
{
var i;
var xml = xtermlist.responseXML;
- var body = document.getElementById("termlist");
+ var body = facet_list[cur_facet][1];
var hits = xml.getElementsByTagName("term");
var clients =
Number(xml.getElementsByTagName("activeclients")[0].childNodes[0].nodeValue);
+
+ cur_facet++;
+
+ if (cur_facet >= facet_list.length)
+ cur_facet = 0;
+
if (!hits[0])
{
- termtimer = setTimeout(check_termlist, 1000);
+ termtimer = setTimeout(check_termlist, 500);
}
else
{
- body.innerHTML = "<b>Limit results:</b><br>";
- show_termlistoptions(body);
- for (i = 0; i < hits.length; i++)
+ body.innerHTML = '';
+
+ for (i = 0; i < hits.length; i++)
{
var namen = hits[i].getElementsByTagName("name");
if (namen[0])
body.innerHTML += '<a href="#" onclick="refine_query(this)">' +
namen[0].childNodes[0].nodeValue +
'</a>';
- body.innerHTML += '<br>';
}
+
if (clients > 0)
- termtimer = setTimeout(check_termlist, 2000);
+ termtimer = setTimeout(check_termlist, 1000);
}
}
function check_termlist()
{
+ var facet_name = facet_list[cur_facet][0];
var url = "search.pz2?" +
"command=termlist" +
"&session=" + session +
- "&name=" + cur_termlist;
+ "&name=" + facet_name;
xtermlist = GetXmlHttpObject();
xtermlist.onreadystatechange=show_termlist;
xtermlist.open("GET", url);
xsearch.onreadystatechange=search_started;
xsearch.open("GET", url);
xsearch.send(null);
- document.getElementById("termlist").innerHTML = '';
+// document.getElementById("termlist").innerHTML = '';
document.getElementById("body").innerHTML = '';
update_history();
shown = 0;
}
+function get_available_facets () {
+ var facet_container = document.getElementById('termlists');
+ var facet_cells = facet_container.childNodes;
+ var facets = Array();
+ var i;
+
+ for (i = 0; i < facet_cells.length; i++) {
+ var cell = facet_cells.item(i);
+
+ if (cell.className == 'facet') {
+ var facet_name = cell.id.replace(/^facet_([^_]+)_terms$/, "$1");
+ facets.push(Array(facet_name, cell));
+ }
+ }
+
+ return facets;
+}
+
+
function get_facet_container (obj) {
return document.getElementById(obj.id + '_terms');
}
if (obj.className == 'selected') {
obj.className = 'unselected';
- container.style.display = 'block';
+ container.style.display = 'inline';
} else {
obj.className = 'selected';
container.style.display = 'none';