function xmlhttpPost() { var searchform = document.forms['searchform']; 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()); } } self.xmlHttpReq.send(null); } function navget(list, name) { for (var i = 0; i < list.length; i++) { if (list[i].facetname == name) return list[i]; } } 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) { 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(/[,.]/,""); // var startIndex = firstChannel.startIndex; // var itemsPerPage = firstChannel.itemsPerPage; var navigation = firstChannel.navigation; var topics = navget(navigation, "topics"); // 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]; } // 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.
"; html += "
"; } else { if (query == "") { html += "please enter some search words"; } else { html += "no results"; } } html += "
"; // add extension navigation var extnav = ""; for (var key in filetypes) { if (filetypes[key] > 0) { extnav += "" + key + "(" + filetypes[key] + ")  ";} } if (extnav.length > 0) { html += "apply a filter by filetype:    " + extnav; } // add topic navigation if (topics && topics.length > 0) { var topwords = ""; for (var i = 0; i < topics.elements.length; i++) { topwords += "" + topics.elements[i].name + " "; if (i > 10) break; } html += "   topwords: " + topwords; } html += "

"; // display result if (firstChannel.items.length > 0) { var item; 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 += "
ProtocolHostPathNameSizeDescriptionDate
" + protocol + "" + host + "" + path + "" + title + "" + item.sizename + "" + item.description + "" + pd + "
"; } document.getElementById("searchresults").innerHTML = html; hideDownloadScript(); }