diff --git a/htroot/js/yacyinteractive.js b/htroot/js/yacyinteractive.js index 070dede3b..7c0e889c2 100644 --- a/htroot/js/yacyinteractive.js +++ b/htroot/js/yacyinteractive.js @@ -3,25 +3,32 @@ function xmlhttpPost() { search(searchform.query.value); } -function search(query) { -// var xmlHttpReq = false; - start = new Date(); - var self = this; - if (window.XMLHttpRequest) { // Mozilla/Safari - self.xmlHttpReq = new XMLHttpRequest(); - } - else if (window.ActiveXObject) { // IE - self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); - } - self.xmlHttpReq.open('GET', "yacysearch.json?verify=false&resource=local&maximumRecords=1000&nav=all&query=" + query, true); - self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - self.xmlHttpReq.onreadystatechange = function() { - if (self.xmlHttpReq.readyState == 4) { - stop = new Date(); - updatepage(query, self.xmlHttpReq.responseText, stop.getTime() - start.getTime()); - } +// static variables +var start = new Date(); +var query = ""; +var searchresult; +var totalResults = 0; +var filetypes; +var topics; +var script = ""; + +function search(search) { + query = search; + start = new Date(); + var self = this; + if (window.XMLHttpRequest) { // Mozilla/Safari + self.xmlHttpReq = new XMLHttpRequest(); + } else if (window.ActiveXObject) { // IE + self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); + } + self.xmlHttpReq.open('GET', "yacysearch.json?verify=false&resource=local&maximumRecords=1000&nav=all&query=" + query, true); + self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + self.xmlHttpReq.onreadystatechange = function() { + if (self.xmlHttpReq.readyState == 4) { + preparepage(self.xmlHttpReq.responseText); } - self.xmlHttpReq.send(null); + } + self.xmlHttpReq.send(null); } function navget(list, name) { @@ -30,58 +37,39 @@ function navget(list, name) { } } -var searchresult; - -function makeDownloadScript() { - script = "
";
-  for (var i = 0; i < searchresult.length; i++) {
-        var item = searchresult[i];
-        script += "curl -OL \"" + item.link + "\"\n";
-  }
-  script += "
"; - document.getElementById("downloadscript").innerHTML = script; - document.getElementById("downloadbutton").innerHTML = ""; -} - -function hideDownloadScript() { - document.getElementById("downloadscript").innerHTML = ""; - var dlb = document.getElementById("downloadbutton"); - if (dlb) dlb.innerHTML = ""; -} - -function updatepage(query, str, time) { +function preparepage(str) { var raw = document.getElementById("raw"); if (raw != null) raw.innerHTML = str; var rsp = eval("("+str+")"); var firstChannel = rsp.channels[0]; searchresult = firstChannel.items; - var totalResults = firstChannel.totalResults.replace(/[,.]/,""); + totalResults = firstChannel.totalResults.replace(/[,.]/,""); // var startIndex = firstChannel.startIndex; // var itemsPerPage = firstChannel.itemsPerPage; - var navigation = firstChannel.navigation; - var topics = navget(navigation, "topics"); + topics = navget(firstChannel.navigation, "topics"); + filetypes = {}; + script = ""; - // analyse the search result - var filetypes = {}; - for (var i = 0; i < firstChannel.items.length; i++) { - item = firstChannel.items[i]; - if (item.link && item.link.length > 4) { - ext = item.link.substring(item.link.length - 4); - if (ext.charAt(0) == ".") { - ext = ext.substring(1).toLowerCase(); - var count = filetypes[ext]; - if (count) filetypes[ext]++; else filetypes[ext] = 1; - } - } - } - for (var key in filetypes) { - if (query.indexOf("filetype:" + key) >= 0) delete filetypes[key]; - } + document.getElementById("searchresults").innerHTML = resultList(); + document.getElementById("searchnavigation").innerHTML = resultStart(); + hideDownloadScript(); +} + +function makeDownloadScript() { + document.getElementById("downloadscript").innerHTML = "
" + script + "
"; + document.getElementById("downloadbutton").innerHTML = ""; +} + +function hideDownloadScript() { + document.getElementById("downloadscript").innerHTML = ""; + var dlb = document.getElementById("downloadbutton"); + if (dlb) dlb.innerHTML = ""; +} - // show statistics - var html = ""; - if (firstChannel.items.length > 0) { - html += "
" + firstChannel.items.length + " results from a total of " + totalResults + " docs in index; search time: " + time + " milliseconds.
"; +function resultStart() { + var html = ""; + if (totalResults > 0) { + html += "
" + searchresult.length + " results from a total of " + totalResults + " docs in index; search time: " + ((new Date()).getTime() - start.getTime()) + " milliseconds.
"; html += "
"; } else { if (query == "") { @@ -90,18 +78,26 @@ function updatepage(query, str, time) { html += "no results"; } } - html += "
"; + html += "
"; // add extension navigation var extnav = ""; for (var key in filetypes) { - if (filetypes[key] > 0) { extnav += "" + key + "(" + filetypes[key] + ")  ";} + if (filetypes[key] > 0) { + extnav += "" + key + "(" + filetypes[key] + ")  "; + } } if (extnav.length > 0) { - html += "apply a filter by filetype:    " + extnav; + html += "apply a filter by filetype:    " + extnav + ""; + } else { + // check if there is a filetype constraint and offer a removal + if (query.length >= 13 && query.substring(query.length - 13, query.length - 3) == " filetype:") { + html += "remote the filter '" + query.substring(query.length - 12) + "'"; + } } - // add topic navigation + // add topic navigation + /* if (topics && topics.length > 0) { var topwords = ""; for (var i = 0; i < topics.elements.length; i++) { @@ -110,50 +106,78 @@ function updatepage(query, str, time) { } html += "   topwords: " + topwords; } - html += "

"; - - // display result - if (firstChannel.items.length > 0) { + */ + return html; +} + +function resultList() { + var html = ""; + if (searchresult.length > 0) { var item; - html += ""; + html += "
"; html += ""; html += ""; html += ""; - html += ""; - html += ""; - html += ""; + html += ""; + html += ""; + html += ""; //html += ""; - html += ""; - for (var i = 0; i < firstChannel.items.length; i++) { - item = firstChannel.items[i]; - p = item.link.indexOf("//"); - protocol = ""; - host = ""; - path = item.link; - if (p > 0) { - q = item.link.indexOf("/", p + 2); - protocol = item.link.substring(0, p - 1); - host = item.link.substring(p + 2, q); - path = item.link.substring(q + 1); - } - html += ""; - html += ""; - html += ""; - html += ""; - title = item.title; - if (title == "") title = path; - html += ""; - html += ""; - //html += ""; - pd = item.pubDate; - if (pd.substring(pd.length - 6) == " +0000") pd = pd.substring(0, pd.length - 6); - if (pd.substring(pd.length - 9) == " 00:00:00") pd = pd.substring(0, pd.length - 9); - if (pd.substring(pd.length - 5) == " 2010") pd = pd.substring(0, pd.length - 5); - html += ""; - html += ""; + html += ""; + for (var i = 0; i < searchresult.length; i++) { + var item = searchresult[i]; + html += resultLine(item); } html += "
ProtocolHostPathNameSizePathNameSizeDescriptionDate
" + protocol + "" + host + "" + path + "" + title + "" + item.sizename + "" + item.description + "" + pd + "
Date
"; } - document.getElementById("searchresults").innerHTML = html; - hideDownloadScript(); -} \ No newline at end of file + return html; +} + +function resultLine(item) { + var html = ""; + p = item.link.indexOf("//"); + protocol = ""; + host = ""; + path = item.link; + if (p > 0) { + q = item.link.indexOf("/", p + 2); + protocol = item.link.substring(0, p - 1); + host = item.link.substring(p + 2, q); + path = item.link.substring(q + 1); + } + if (path.length >= 40) path = path.substring(0, 18) + "..." + path.substring(path.length - 19); + html += ""; + html += "" + protocol + ""; + html += "" + host + ""; + html += "" + path + ""; + title = item.title; + if (title == "") title = path; + if (title.length >= 60) title = title.substring(0, 28) + "..." + title.substring(title.length - 29); + html += "" + title + ""; + html += "" + item.sizename + ""; + //html += "" + item.description + ""; + pd = item.pubDate; + if (pd.substring(pd.length - 6) == " +0000") pd = pd.substring(0, pd.length - 6); + if (pd.substring(pd.length - 9) == " 00:00:00") pd = pd.substring(0, pd.length - 9); + if (pd.substring(pd.length - 5) == " 2010") pd = pd.substring(0, pd.length - 5); + html += "" + pd + ""; + html += ""; + + // update navigation + if (item.link && item.link.length > 4) { + ext = item.link.substring(item.link.length - 4); + if (ext.charAt(0) == "." && ext.charAt(3) != "/") { + ext = ext.substring(1).toLowerCase(); + var count = filetypes[ext]; + if (count) filetypes[ext]++; else filetypes[ext] = 1; + } + } + for (var key in filetypes) { + if (query.indexOf("filetype:" + key) >= 0) delete filetypes[key]; + } + + // update download script + script += "curl -OL \"" + item.link + "\"\n"; + + // return table row + return html; +} diff --git a/htroot/yacyinteractive.html b/htroot/yacyinteractive.html index fa54b8088..cbad0cda9 100644 --- a/htroot/yacyinteractive.html +++ b/htroot/yacyinteractive.html @@ -29,17 +29,18 @@ To see a list of all APIs, please visit the +
+
-
+
+
+