@ -3,25 +3,32 @@ function xmlhttpPost() {
search ( searchform . query . value ) ;
search ( searchform . query . value ) ;
}
}
function search ( query ) {
// static variables
// var xmlHttpReq = false;
var start = new Date ( ) ;
start = new Date ( ) ;
var query = "" ;
var self = this ;
var searchresult ;
if ( window . XMLHttpRequest ) { // Mozilla/Safari
var totalResults = 0 ;
self . xmlHttpReq = new XMLHttpRequest ( ) ;
var filetypes ;
}
var topics ;
else if ( window . ActiveXObject ) { // IE
var script = "" ;
self . xmlHttpReq = new ActiveXObject ( "Microsoft.XMLHTTP" ) ;
}
function search ( search ) {
self . xmlHttpReq . open ( 'GET' , "yacysearch.json?verify=false&resource=local&maximumRecords=1000&nav=all&query=" + query , true ) ;
query = search ;
self . xmlHttpReq . setRequestHeader ( 'Content-Type' , 'application/x-www-form-urlencoded' ) ;
start = new Date ( ) ;
self . xmlHttpReq . onreadystatechange = function ( ) {
var self = this ;
if ( self . xmlHttpReq . readyState == 4 ) {
if ( window . XMLHttpRequest ) { // Mozilla/Safari
stop = new Date ( ) ;
self . xmlHttpReq = new XMLHttpRequest ( ) ;
updatepage ( query , self . xmlHttpReq . responseText , stop . getTime ( ) - start . getTime ( ) ) ;
} 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 ) {
function navget ( list , name ) {
@ -30,58 +37,39 @@ function navget(list, name) {
}
}
}
}
var searchresult ;
function preparepage ( str ) {
function makeDownloadScript ( ) {
script = "<div style=\"float:left\"><pre>" ;
for ( var i = 0 ; i < searchresult . length ; i ++ ) {
var item = searchresult [ i ] ;
script += "curl -OL \"" + item . link + "\"\n" ;
}
script += "</pre></div>" ;
document . getElementById ( "downloadscript" ) . innerHTML = script ;
document . getElementById ( "downloadbutton" ) . innerHTML = "<input id=\"downloadbutton\" type=\"button\" value=\"hide the download script\" onClick=\"hideDownloadScript();\"/></form>" ;
}
function hideDownloadScript ( ) {
document . getElementById ( "downloadscript" ) . innerHTML = "" ;
var dlb = document . getElementById ( "downloadbutton" ) ;
if ( dlb ) dlb . innerHTML = "<input type=\"button\" value=\"create a download script\" onClick=\"makeDownloadScript();\"/></form>" ;
}
function updatepage ( query , str , time ) {
var raw = document . getElementById ( "raw" ) ;
var raw = document . getElementById ( "raw" ) ;
if ( raw != null ) raw . innerHTML = str ;
if ( raw != null ) raw . innerHTML = str ;
var rsp = eval ( "(" + str + ")" ) ;
var rsp = eval ( "(" + str + ")" ) ;
var firstChannel = rsp . channels [ 0 ] ;
var firstChannel = rsp . channels [ 0 ] ;
searchresult = firstChannel . items ;
searchresult = firstChannel . items ;
var totalResults = firstChannel . totalResults . replace ( /[,.]/ , "" ) ;
totalResults = firstChannel . totalResults . replace ( /[,.]/ , "" ) ;
// var startIndex = firstChannel.startIndex;
// var startIndex = firstChannel.startIndex;
// var itemsPerPage = firstChannel.itemsPerPage;
// var itemsPerPage = firstChannel.itemsPerPage;
var navigation = firstChannel . navigation ;
topics = navget ( firstChannel . navigation , "topics" ) ;
var topics = navget ( navigation , "topics" ) ;
filetypes = { } ;
script = "" ;
// analyse the search result
document . getElementById ( "searchresults" ) . innerHTML = resultList ( ) ;
var filetypes = { } ;
document . getElementById ( "searchnavigation" ) . innerHTML = resultStart ( ) ;
for ( var i = 0 ; i < firstChannel . items . length ; i ++ ) {
hideDownloadScript ( ) ;
item = firstChannel . items [ i ] ;
}
if ( item . link && item . link . length > 4 ) {
ext = item . link . substring ( item . link . length - 4 ) ;
function makeDownloadScript ( ) {
if ( ext . charAt ( 0 ) == "." ) {
document . getElementById ( "downloadscript" ) . innerHTML = "<div style=\"float:left\"><pre>" + script + "</pre></div>" ;
ext = ext . substring ( 1 ) . toLowerCase ( ) ;
document . getElementById ( "downloadbutton" ) . innerHTML = "<input id=\"downloadbutton\" type=\"button\" value=\"hide the download script\" onClick=\"hideDownloadScript();\"/>" ;
var count = filetypes [ ext ] ;
}
if ( count ) filetypes [ ext ] ++ ; else filetypes [ ext ] = 1 ;
}
function hideDownloadScript ( ) {
}
document . getElementById ( "downloadscript" ) . innerHTML = "" ;
}
var dlb = document . getElementById ( "downloadbutton" ) ;
for ( var key in filetypes ) {
if ( dlb ) dlb . innerHTML = "<input type=\"button\" value=\"create a download script\" onClick=\"makeDownloadScript();\"/>" ;
if ( query . indexOf ( "filetype:" + key ) >= 0 ) delete filetypes [ key ] ;
}
}
// show statistics
function resultStart ( ) {
var html = "<span id=\"resCounter\" style=\"display: inline; \">";
var html = "<span style=\"display:block \">";
if ( firstChannel. items . length > 0 ) {
if ( totalResults > 0 ) {
html += "<form><div style=\"float:left\">" + firstChannel. items . length + " results from a total of " + totalResults + " docs in index; search time: " + time + " milliseconds. </div>" ;
html += "<form><div style=\"float:left\">" + searchresult . length + " results from a total of " + totalResults + " docs in index; search time: " + ( ( new Date ( ) ) . ge tT ime( ) - start . getTime ( ) ) + " milliseconds. </div>" ;
html += "<div id=\"downloadbutton\" style=\"float:left\"></div></form>" ;
html += "<div id=\"downloadbutton\" style=\"float:left\"></div></form>" ;
} else {
} else {
if ( query == "" ) {
if ( query == "" ) {
@ -90,18 +78,26 @@ function updatepage(query, str, time) {
html += "no results" ;
html += "no results" ;
}
}
}
}
html += "< br >";
html += "< /span >";
// add extension navigation
// add extension navigation
var extnav = "" ;
var extnav = "" ;
for ( var key in filetypes ) {
for ( var key in filetypes ) {
if ( filetypes [ key ] > 0 ) { extnav += "<a style=\"text-decoration:underline\" href=\"/yacyinteractive.html?query=" + query + "+filetype:" + key + "\">" + key + "</a>(" + filetypes [ key ] + ") " ; }
if ( filetypes [ key ] > 0 ) {
extnav += "<a style=\"text-decoration:underline\" href=\"/yacyinteractive.html?query=" + query + "+filetype:" + key + "\">" + key + "</a>(" + filetypes [ key ] + ") " ;
}
}
}
if ( extnav . length > 0 ) {
if ( extnav . length > 0 ) {
html += "apply a <b>filter</b> by filetype: " + extnav ;
html += "<span style=\"display:block\">apply a <b>filter</b> by filetype: " + extnav + "</span>" ;
} 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 += "<span style=\"display:block\"><a style=\"text-decoration:underline\" href=\"/yacyinteractive.html?query=" + query . substring ( 0 , query . length - 12 ) + "\">remote the filter '" + query . substring ( query . length - 12 ) + "'</a></span>" ;
}
}
}
// add topic navigation
// add topic navigation
/ *
if ( topics && topics . length > 0 ) {
if ( topics && topics . length > 0 ) {
var topwords = "" ;
var topwords = "" ;
for ( var i = 0 ; i < topics . elements . length ; i ++ ) {
for ( var i = 0 ; i < topics . elements . length ; i ++ ) {
@ -110,50 +106,78 @@ function updatepage(query, str, time) {
}
}
html += " topwords: " + topwords ;
html += " topwords: " + topwords ;
}
}
html += "<br><div id=\"downloadscript\"></div></span><br>" ;
* /
return html ;
// display result
}
if ( firstChannel . items . length > 0 ) {
function resultList ( ) {
var html = "" ;
if ( searchresult . length > 0 ) {
var item ;
var item ;
html += "<table class=\"sortable\" id=\"sortable\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" width=\"99%\">" ;
html += "<table class=\"sortable\" id=\"sortable\" border=\"0\" cellpadding=\" 0 \" cellspacing=\"1\" width=\"99%\">";
html += "<tr class=\"TableHeader\" valign=\"bottom\">" ;
html += "<tr class=\"TableHeader\" valign=\"bottom\">" ;
html += "<td width=\"40\">Protocol</td>" ;
html += "<td width=\"40\">Protocol</td>" ;
html += "<td width=\"60\">Host</td>" ;
html += "<td width=\"60\">Host</td>" ;
html += "<td width=\" 60\">Path</td>";
html += "<td width=\" 2 60\">Path</td>";
html += "<td width=\" 60\">Name</td>";
html += "<td width=\" 3 60\">Name</td>";
html += "<td width=\" 5 0\">Size</td>";
html += "<td width=\" 6 0\">Size</td>";
//html += "<td>Description</td>";
//html += "<td>Description</td>";
html += "<td width=\"50\">Date</td></tr>" ;
html += "<td width=\"70\">Date</td></tr>" ;
for ( var i = 0 ; i < firstChannel . items . length ; i ++ ) {
for ( var i = 0 ; i < searchresult . length ; i ++ ) {
item = firstChannel . items [ i ] ;
var item = searchresult [ i ] ;
p = item . link . indexOf ( "//" ) ;
html += resultLine ( item ) ;
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 += "<tr class=\"TableCellLight\">" ;
html += "<td align=\"left\">" + protocol + "</td>" ;
html += "<td align=\"left\"><a href=\"" + protocol + "://" + host + "/" + "\">" + host + "</a></td>" ;
html += "<td align=\"left\"><a href=\"" + item . link + "\">" + path + "</a></td>" ;
title = item . title ;
if ( title == "" ) title = path ;
html += "<td align=\"left\"><a href=\"" + item . link + "\">" + title + "</a></td>" ;
html += "<td align=\"right\">" + item . sizename + "</td>" ;
//html += "<td>" + item.description + "</td>";
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 += "<td align=\"right\">" + pd + "</td>" ;
html += "</tr>" ;
}
}
html += "</table>" ;
html += "</table>" ;
}
}
document . getElementById ( "searchresults" ) . innerHTML = html ;
return html ;
hideDownloadScript ( ) ;
}
}
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 += "<tr class=\"TableCellLight\">" ;
html += "<td align=\"left\">" + protocol + "</td>" ;
html += "<td align=\"left\"><a href=\"" + protocol + "://" + host + "/" + "\">" + host + "</a></td>" ;
html += "<td align=\"left\"><a href=\"" + item . link + "\">" + path + "</a></td>" ;
title = item . title ;
if ( title == "" ) title = path ;
if ( title . length >= 60 ) title = title . substring ( 0 , 28 ) + "..." + title . substring ( title . length - 29 ) ;
html += "<td align=\"left\"><a href=\"" + item . link + "\">" + title + "</a></td>" ;
html += "<td align=\"right\">" + item . sizename + "</td>" ;
//html += "<td>" + item.description + "</td>";
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 += "<td align=\"right\">" + pd + "</td>" ;
html += "</tr>" ;
// 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 ;
}