function xmlhttpPost() { var searchform = document.forms['searchform']; var rsslink = document.getElementById("rsslink"); if (rsslink != null) rsslink.href="yacysearch.rss?query=" + searchform.query.value; search(searchform.query.value, searchform.maximumRecords.value, searchform.startRecord.value); } // static variables var start = new Date(); var query = ""; var maximumRecords = "1000"; var startRecord = "0"; var searchresult; var totalResults = 0; var filetypes; var topics; var script = ""; var modifier = ""; var modifiertype = ""; function search(search, count, offset) { var navhtml = document.getElementById("searchnavigation"); if (navhtml != null) navhtml.innerHTML = "
loading from local index...
"; query = search; maximumRecords = count; if (count == "") maximumRecords = 100; startRecord = offset; if (offset == "") startRecord = 0; start = new Date(); if (query == null || query == "") { return; } 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&nav=all&contentdom=all&maximumRecords=" + maximumRecords + "&startRecord=" + startRecord + "&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); } function navget(list, name) { for (var i = 0; i < list.length; i++) { if (list[i].facetname == name) return list[i]; } } function preparepage(str) { document.getElementById("searchnavigation").innerHTML = "
parsing result...
"; var raw = document.getElementById("raw"); if (raw != null) raw.innerHTML = str; var rsp = eval("(" + str + ")"); var firstChannel = rsp.channels[0]; searchresult = firstChannel.items; totalResults = firstChannel.totalResults.replace(/[,.]/,""); // var startIndex = firstChannel.startIndex; // var itemsPerPage = firstChannel.itemsPerPage; topics = navget(firstChannel.navigation, "topics"); filetypes = {}; script = ""; if (query.length >= 13 && query.substring(query.length - 13, query.length - 3) == " filetype:") { modifier = query.substring(query.length - 12); } if (modifier != "") modifiertype = modifier.substring(modifier.length - 3) if (modifiertype == "png" || modifiertype == "gif" || modifiertype == "jpg") { var tt = resultImages(); document.getElementById("searchresults").innerHTML = tt; } else { var tt = resultList(); document.getElementById("searchresults").innerHTML = tt; } var tt = resultNavigation(); document.getElementById("searchnavigation").innerHTML = tt; document.getElementById("serverlist").innerHTML = ""; 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 = ""; } function resultNavigation() { var html = ""; if (searchresult.length > totalResults) totalResults = searchresult.length; if (totalResults > 0) { html += "
" + searchresult.length + " results from a total of " + totalResults + " docs in index; search time: " + ((new Date()).getTime() - start.getTime()) + " milliseconds. "; html += "
"; html += "
"; if (maximumRecords != 10 && totalResults >= 10) html += ""; if (maximumRecords != 100 && totalResults >= 100) html += ""; if (maximumRecords != 1000 && totalResults >= 1000) html += ""; if (totalResults <= 10000 && maximumRecords < totalResults) html += ""; html += "
"; // for inline html += "
"; // for result statistic wrapper } else { if (query == "") { html += "please enter some search wordsor use the following predefined search queries:"; html += "find images: "; html += "(png),"; html += "(gif),"; html += "(jpg)
"; html += "list: "; html += "recent pdf
"; //html += ""; } else { html += "no results"; } } // 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 + "
"; } else { // check if there is a filetype constraint and offer a removal if (modifier != "") { html += "remove the filter '" + modifier + "'"; } } // 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; } */ return html; } function resultList() { var html = ""; if (searchresult.length > 0) { document.getElementById("searchnavigation").innerHTML = "
found " + searchresult.length + " documents, preparing table...
"; html += ""; html += ""; for (var i = 0; i < searchresult.length; i++) { html += resultLine("row", searchresult[i], i + 1); } html += "
countProtocolHostPathNameSizeDate
"; } return html; } function resultImages() { var html = ""; document.getElementById("searchnavigation").innerHTML = "
found " + searchresult.length + " images, preparing...
"; for (var i = 0; i < searchresult.length; i++) { html += resultLine("image", searchresult[i]); } return html; } function resultLine(type, item, linenumber) { // evaluate item if (item == null) return ""; if (item.link == null) return ""; 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); } title = item.title; q = path.lastIndexOf("/"); if (q > 0) path = path.substring(0, q); path = unescape(path); if (path.length >= 40) path = path.substring(0, 18) + "..." + path.substring(path.length - 19); if (title == "") title = path; if (title.length >= 60) title = title.substring(0, 28) + "..." + title.substring(title.length - 29); 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); // 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 if (item.link.indexOf("smb://") >= 0) script += "smbget -n -a -r \"" + item.link + "\"\n"; else script += "curl -OL \"" + item.link + "\"\n"; // make table row var html = ""; if (type == "row") { html += ""; html += "" + linenumber + ""; html += "" + protocol + ""; html += "" + host + ""; html += "" + path + ""; html += "" + title + ""; if (item.sizename == "-1 bytes") html += ""; else html += "" + item.sizename + ""; //html += "" + item.description + ""; html += "" + pd + ""; html += ""; } if (type == "image") { html += "
"; html += ""; //html += "\"""; html += "\"""; html += ""; var name = title; while ((p = name.indexOf("/")) >= 0) { name = name.substring(p + 1); } html += ""; html += "
"; } // return entry return html; }