X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;f=www%2Fdemo%2Fsearch.js;h=6762753bf96462f6926de2f4e8ce88e5a58faee5;hb=dd28cba99bce512b6b4762a6ba99dc96ca109768;hp=feed8f83d45416b523c0320c8e9b346df3362f6a;hpb=d5691695e6a22fc0db9c9bffc9ed6f85e908d8c1;p=pazpar2-moved-to-github.git diff --git a/www/demo/search.js b/www/demo/search.js index feed8f8..6762753 100644 --- a/www/demo/search.js +++ b/www/demo/search.js @@ -1,4 +1,4 @@ -/* $Id: search.js,v 1.32 2007-01-16 19:42:20 quinn Exp $ +/* $Id: search.js,v 1.41 2007-01-18 17:42:39 quinn Exp $ * --------------------------------------------------- * Javascript container */ @@ -24,7 +24,6 @@ var url_surveillence; var recstoshow = 20; var page_window = 5; // Number of pages prior to and after the current page var facet_list; -var cur_facet = 0; var cur_sort = "relevance"; var searched = 0; var cur_id = -1; @@ -96,7 +95,8 @@ function session_pinged() var error = xml.getElementsByTagName("error"); if (error[0]) location = "?"; - setTimeout(ping_session, 50000); + else + setTimeout(ping_session, 50000); } function update_action (new_action) { @@ -222,6 +222,16 @@ function displayname(name) return 'ISBN'; else if (name == 'md-publisher') return 'Publisher'; + else if (name == 'md-url') + return 'URL'; + else if (name == 'md-title') + return '@'; + else if (name == 'md-id') + return 'Local ID'; + else if (name == 'recid') + return '@'; + else if (name == 'location') + return '@'; else return name; } @@ -232,6 +242,8 @@ function hyperlink_field(name) return 'au'; else if (name == 'md-subject') return 'su'; + else if (name == 'md-url') + return 'URL'; else return 0; } @@ -242,7 +254,7 @@ function paint_details_tr(name, dn) var dname = displayname(name); var ln = create_element('b', dname); var tln = document.createElement('td'); - tln.setAttribute('width', 70); + tln.setAttribute('width', 90); tln.setAttribute('valign', 'top'); tln.appendChild(ln); var tr = document.createElement('tr'); @@ -251,17 +263,12 @@ function paint_details_tr(name, dn) return tr; } -function paint_details(body, xml) +function paint_data_elements(target, node) { - // This is some ugly display code. Replace with your own ting o'beauty - clear_cell(body); - //body.appendChild(document.createElement('br')); - var nodes = xml.childNodes[0].childNodes; - var i; - var table = document.createElement('table'); - table.setAttribute('cellpadding', 2); + var nodes = node.childNodes; var dn = 0; var lastname = ''; + var i; for (i = 0; i < nodes.length; i++) { if (nodes[i].nodeType != 1) @@ -269,17 +276,21 @@ function paint_details(body, xml) var name = nodes[i].nodeName; if (name == 'recid' || name == 'md-title') continue; - if (name != lastname) + if (name != lastname && lastname != 'location') { if (dn) { var tr = paint_details_tr(lastname, dn); - table.appendChild(tr); + target.appendChild(tr); } dn = document.createElement('td'); lastname = name; } - + if (name == 'location') + { + target.appendChild(paint_details_tr('Location', paint_subrecord(nodes[i]))); + continue; + } if (!nodes[i].childNodes[0]) continue; var value = nodes[i].childNodes[0].nodeValue; @@ -290,20 +301,46 @@ function paint_details(body, xml) if (hyl) { nv = create_element('a', value); - nv.setAttribute('href', '#'); - nv.setAttribute('term', value); - nv.setAttribute('searchfield', hyl); - nv.onclick = function() { hyperlink_search(this); return false; }; + if (hyl == 'URL') + { + nv.setAttribute('href', value); + nv.setAttribute('target', '_blank'); + } + else + { + nv.setAttribute('href', '#'); + nv.setAttribute('term', value); + nv.setAttribute('searchfield', hyl); + nv.onclick = function() { hyperlink_search(this); return false; }; + } } else nv = document.createTextNode(value); dn.appendChild(nv); } - if (dn) + if (dn && lastname != 'location') { var tr = paint_details_tr(lastname, dn); - table.appendChild(tr); + target.appendChild(tr); } +} + +function paint_subrecord(node) +{ + var table = document.createElement('table'); + var zurl = node.getAttribute('id'); + var tr = paint_details_tr('Source', document.createTextNode(zurl)); + table.appendChild(tr); + paint_data_elements(table, node); + return table; +} + +function paint_details(body, xml) +{ + clear_cell(body); + var table = document.createElement('table'); + table.setAttribute('cellpadding', 2); + paint_data_elements(table, xml.childNodes[0]); body.appendChild(table); body.style.display = 'inline'; } @@ -329,6 +366,15 @@ function show_details() cur_id = id; cur_rec = xml; + var nodes = document.getElementsByName('listrecord'); + var i; + for (i = 0; i < nodes.length; i++) + { + var dets = nodes[i].getElementsByTagName('div'); + if (dets[0]) + dets[0].style.display = 'none'; + } + var body = document.getElementById('rec_' + id); if (!body) return; @@ -347,14 +393,6 @@ function hyperlink_search(obj) function fetch_details(id) { cur_id = -1; - var nodes = document.getElementsByName('listrecord'); - var i; - for (i = 0; i < nodes.length; i++) - { - var dets = nodes[i].getElementsByTagName('div'); - if (dets[0]) - dets[0].style.display = 'none'; - } if (id == cur_id) { cur_id = -1; @@ -435,7 +473,7 @@ function show_records() record_div.setAttribute('name', 'listrecord'); var record_cell = create_element('a', title); - record_cell.setAttribute('href', '#'); + record_cell.setAttribute('href', '#' + id); record_cell.setAttribute('onclick', 'fetch_details(' + id + '); return false'); record_div.appendChild(record_cell); if (author) @@ -500,75 +538,81 @@ function refine_query (obj) { term = term.replace(/[\(\)]/g, ''); if (cur_termlist == 'subject') - query_cell.value += ' and su=(' + term + ')'; + query_cell.value += ' and su=' + term; else if (cur_termlist == 'author') - query_cell.value += ' and au=(' + term + ')'; + query_cell.value += ' and au=' + term; + else if (cur_termlist == 'date') + query_cell.value += ' and date=' + term; start_search(); } +function clear_termlists() +{ + var i; + for (i = 0; i < facet_list.length; i++) + clear_cell(facet_list[i][1]); +} - -function show_termlist() +function show_termlists() { if (xtermlist.readyState != 4) return; var i; var xml = xtermlist.responseXML; - var body = facet_list[cur_facet][1]; - var facet_name = facet_list[cur_facet][0]; - var hits = xml.getElementsByTagName("term"); var clients = Number(xml.getElementsByTagName("activeclients")[0].childNodes[0].nodeValue); + var lists = xml.getElementsByTagName("list"); - cur_facet++; - - if (cur_facet >= facet_list.length) - cur_facet = 0; - - if (!hits[0]) - { - termtimer = setTimeout(check_termlist, 500); - } - else + for (i = 0; i < lists.length; i++) { + var listname = lists[i].getAttribute('name'); + var body = document.getElementById('facet_' + listname + '_terms'); + if (body.style.display == 'none') + continue; clear_cell(body); - - for (i = 0; i < hits.length; i++) + var terms = lists[i].getElementsByTagName('term'); + var t; + for (t = 0; t < terms.length; t++) { - var namen = hits[i].getElementsByTagName("name"); - var freqn = hits[i].getElementsByTagName("frequency"); + var namen = terms[t].getElementsByTagName("name"); + var freqn = terms[t].getElementsByTagName("frequency"); if (namen[0]) var term = namen[0].childNodes[0].nodeValue; var freq = freqn[0].childNodes[0].nodeValue; var refine_cell = create_element('a', term + ' (' + freq + ')'); refine_cell.setAttribute('href', '#'); refine_cell.setAttribute('term', term); - refine_cell.setAttribute('facet', facet_name); + refine_cell.setAttribute('facet', listname); refine_cell.onclick = function () { refine_query(this); return false; }; body.appendChild(refine_cell); } - - if (clients > 0) - termtimer = setTimeout(check_termlist, 1000); } + if (clients > 0) + termtimer = setTimeout(check_termlist, 1000); } function check_termlist() { - var facet_name = facet_list[cur_facet][0]; + var facet_names = ''; + var i; + for (i = 0; i < facet_list.length; i++) + if (facet_list[i][1].style.display != 'none') + { + if (facet_names) + facet_names += ','; + facet_names += facet_list[i][0]; + } var url = "search.pz2?" + "command=termlist" + "&session=" + session + - "&name=" + facet_name; - xtermlist = GetXmlHttpObject(); - xtermlist.onreadystatechange=show_termlist; - xtermlist.open("GET", url); - xtermlist.send(null); + "&name=" + facet_names + + "&num=12"; + SendXmlHttpObject(xtermlist = GetXmlHttpObject(), url, show_termlists); } function show_stat() @@ -643,6 +687,7 @@ function start_search() clearTimeout(showtimer); showtimer = 0; cur_id = -1; + clear_termlists(); var query = escape(document.getElementById('query').value); var url = "search.pz2?" + "command=search" + @@ -768,6 +813,7 @@ function toggle_facet (obj) { if (obj.className == 'selected') { obj.className = 'unselected'; container.style.display = 'inline'; + check_termlist(); } else { obj.className = 'selected'; container.style.display = 'none';