enhanced interactive search

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5571 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
orbiter 2009-02-04 15:59:22 +00:00
parent 5b79221037
commit 86763c42c4
4 changed files with 48 additions and 23 deletions

View File

@ -5,6 +5,12 @@
#%env/templates/metas.template%#
<script language="Javascript">
function xmlhttpPost() {
var searchform = document.forms['searchform'];
search(searchform.query.value);
}
function search(query) {
var xmlHttpReq = false;
var self = this;
if (window.XMLHttpRequest) { // Mozilla/Safari
@ -13,8 +19,7 @@ function xmlhttpPost() {
else if (window.ActiveXObject) { // IE
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
var searchform = document.forms['searchform'];
self.xmlHttpReq.open('GET', "yacysearch.json?verify=false&resource=local&maximumRecords=100&query=" + searchform.query.value, true);
self.xmlHttpReq.open('GET', "yacysearch.json?verify=false&resource=local&maximumRecords=100&query=" + query, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
@ -24,7 +29,7 @@ function xmlhttpPost() {
self.xmlHttpReq.send(null);
}
function updatepage(str){
function updatepage(str) {
var raw = document.getElementById("raw");
if (raw != null) raw.innerHTML = str;
var rsp = eval("("+str+")");
@ -32,25 +37,42 @@ function updatepage(str){
var totalResults = firstChannel.totalResults;
var startIndex = firstChannel.startIndex;
var itemsPerPage = firstChannel.itemsPerPage;
var html = "<br>total results = " + totalResults;
var item;
html += "<table class=\"networkTable\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\">";
html += "<tr class=\"TableHeader\" valign=\"bottom\">";
html += "<td>Name</td>";
//html += "<td>Description</td>";
html += "<td>Link</td></tr>";
for (var i = 0; i < firstChannel.items.length; i++) {
item = firstChannel.items[i];
html += "<tr class=\"TableCellLight\"><td>"+ item.title + "</td>";
//html += "<td>" + item.description + "</td>";
html += "<td><a href=\"" + item.link + "\">" + item.link + "</a></td></tr>";
var html = "<span id=\"resCounter\" style=\"display: inline;\">total results = " + totalResults;
if (firstChannel.topwords.length > 0) {
var topwords = "";
for (var i = 0; i < firstChannel.topwords.length; i++) {
topwords += "<a href=\"yacyinteractive.html?query=" + firstChannel.searchTerms + "+" + firstChannel.topwords[i].word + "\">" + firstChannel.topwords[i].word + "</a> ";
if (i > 10) break;
}
html += "&nbsp;&nbsp;&nbsp;topwords: " + topwords;
}
html += "</span><br>";
if (totalResults > 0) {
var item;
html += "<table class=\"networkTable\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" width=\"99%\">";
html += "<tr class=\"TableHeader\" valign=\"bottom\">";
html += "<td width=\"30%\">Name</td>";
//html += "<td>Description</td>";
html += "<td>Link</td></tr>";
for (var i = 0; i < firstChannel.items.length; i++) {
item = firstChannel.items[i];
html += "<tr class=\"TableCellLight\"><td>"+ item.title + "</td>";
//html += "<td>" + item.description + "</td>";
html += "<td><a href=\"" + item.link + "\">" + item.link + "</a></td></tr>";
}
html += "</table>";
}
html += "</table>";
document.getElementById("searchresults").innerHTML = html;
}
</script>
</head>
<body>
<script type="text/javascript">
var q = "#[query]#";
if (q != "") search(q);
</script>
#(display)#
#%env/templates/simpleheader.template%#
::
@ -64,16 +86,16 @@ To see a list of all APIs, please visit the <a href="http://www.yacy-websuche.de
#%env/templates/embeddedheader.template%#
#(/display)#
<form class="search small" name="searchform" onkeyup='xmlhttpPost(); return false;'>
<h2>#[promoteSearchPageGreeting]#</h2>
<div class="yacylogo">
<a href="#[promoteSearchPageGreeting.homepage]#" class="yacylogo"><img src="#[promoteSearchPageGreeting.smallImage]#" alt="yacysearch" align="left"/></a></div>
<fieldset class="yacys"><input name="query" type="text" size="50" maxlength="80" /></fieldset>
<div id="searchresults"></div>
<a href="#[promoteSearchPageGreeting.homepage]#" class="yacylogo"><img src="#[promoteSearchPageGreeting.smallImage]#" alt="yacysearch" align="left"/></a>
</div>
<fieldset class="yacys"><input name="query" type="text" value="#[query]#" size="50" maxlength="80" /></fieldset>
<!--<pre>Raw JSON String: <div id="raw"></div></pre>-->
</form>
<div id="searchresults"></div>
#%env/templates/footer.template%#
</body>

View File

@ -50,8 +50,11 @@ public class yacyinteractive {
prop.put("promoteSearchPageGreeting", promoteSearchPageGreeting);
prop.put("promoteSearchPageGreeting.homepage", sb.getConfig(plasmaSwitchboardConstants.GREETING_HOMEPAGE, ""));
prop.put("promoteSearchPageGreeting.smallImage", sb.getConfig(plasmaSwitchboardConstants.GREETING_SMALL_IMAGE, ""));
prop.put("display", display);
String query = (post == null) ? "" : post.get("query", "");
prop.putHTML("query", query);
prop.putHTML("querys", query.replaceAll(" ", "+"));
return prop;
}
}

View File

@ -509,7 +509,7 @@ public class yacysearch {
// for RSS: don't HTML encode some elements
prop.putXML("rss_query", querystring);
prop.put("rss_queryenc", yacyURL.escape(querystring.replace(' ', '+')));
prop.put("rss_queryenc", querystring.replace(' ', '+'));
sb.localSearchLastAccess = System.currentTimeMillis();

View File

@ -1,4 +1,4 @@
"yacy$topwords": [
"topwords": [
#{words}#
{ "word": "#[word]#" }#(nl)#::,#(/nl)#
#{/words}#