From 7ff86d6ba6cb79b2ab0327e972cb123180d30435 Mon Sep 17 00:00:00 2001 From: orbiter Date: Thu, 14 Dec 2006 02:48:37 +0000 Subject: [PATCH] - image search now shows thumbnails (in bad order, but it works) - repaired DHT selection git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3081 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- build.properties | 2 +- htroot/ViewImage.java | 4 +- htroot/js/yacysearch.js | 96 +++++++++++++++++-- htroot/yacysearch.html | 14 ++- htroot/yacysearch.java | 7 +- .../de/anomic/plasma/plasmaSwitchboard.java | 3 +- source/de/anomic/yacy/yacyDHTAction.java | 52 ++++------ 7 files changed, 129 insertions(+), 49 deletions(-) diff --git a/build.properties b/build.properties index 7ef576e44..58511f531 100644 --- a/build.properties +++ b/build.properties @@ -3,7 +3,7 @@ javacSource=1.4 javacTarget=1.4 # Release Configuration -releaseVersion=0.492 +releaseVersion=0.493 releaseFile=yacy_dev_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz #releaseFile=yacy_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz releaseDir=yacy_dev_v${releaseVersion}_${DSTAMP}_${releaseNr} diff --git a/htroot/ViewImage.java b/htroot/ViewImage.java index 30d765ee2..a937f3610 100644 --- a/htroot/ViewImage.java +++ b/htroot/ViewImage.java @@ -74,7 +74,9 @@ public class ViewImage { int timeout = post.getInt("timeout", 5000); // getting the image as stream - InputStream imgStream = (InputStream) sb.snippetCache.getResource(url, true, timeout)[0]; + Object[] resource = sb.snippetCache.getResource(url, true, timeout); + if (resource == null) return null; + InputStream imgStream = (InputStream) resource[0]; if (imgStream == null) return null; // read image data diff --git a/htroot/js/yacysearch.js b/htroot/js/yacysearch.js index c9bc50353..add25abb4 100644 --- a/htroot/js/yacysearch.js +++ b/htroot/js/yacysearch.js @@ -10,14 +10,26 @@ function AllTextSnippets() { } } -function AllMediaSnippets() { +function AllMediaSnippets(mediatype) { var query = document.getElementsByName("former")[0].value; var span = document.getElementsByTagName("span"); for(var x=0;x 0) { + span.className = "snippetLoaded"; + for (i = 0; i < links; i++) { + var type = response.getElementsByTagName("type")[i].firstChild.data; + var href = response.getElementsByTagName("href")[i].firstChild.data; + var name = response.getElementsByTagName("name")[i].firstChild.data; + var attr = response.getElementsByTagName("attr")[i].firstChild.data; + + //
#[name]# + var img = document.createElement("img"); + img.setAttribute("src", "/ViewImage.png?maxwidth=96&maxheight=96&url=" + href); + img.setAttribute("alt", name); + + var imganchor = document.createElement("a"); + imganchor.setAttribute("href", href); + imganchor.appendChild(img); + + var nameanchor = document.createElement("a"); + nameanchor.setAttribute("href", href); + nameanchor.appendChild(document.createTextNode(name)); + + var col1 = document.createElement("td"); + col1.setAttribute("width", "100"); + col1.appendChild(imganchor); + + var row1 = document.createElement("tr"); + row1.setAttribute("class", "TableCellLight"); + row1.appendChild(col1); + + var col2 = document.createElement("td"); + col2.setAttribute("width", "100"); + col2.appendChild(nameanchor); + + var row2 = document.createElement("tr"); + row2.setAttribute("class", "TableCellDark"); + row2.appendChild(col2); + + var table = document.createElement("table"); + table.appendChild(row1); + table.appendChild(row2); + span.appendChild(table); + } + } else { + span.className = "snippetError"; + span.appendChild(document.createTextNode("")); + } +} + + function addHover() { if (document.all&&document.getElementById) { var divs = document.getElementsByTagName("div"); diff --git a/htroot/yacysearch.html b/htroot/yacysearch.html index f38b0b0ca..9d41f115c 100644 --- a/htroot/yacysearch.html +++ b/htroot/yacysearch.html @@ -159,12 +159,24 @@ document.searchform.Enter.value = "search again - catch up more links"; #{/results}# :: + + #{results}# + + loading snippet from #[urlname]# + + #{/results}# + + + :: #{results}# diff --git a/htroot/yacysearch.java b/htroot/yacysearch.java index 179dd85f8..096a2d51c 100644 --- a/htroot/yacysearch.java +++ b/htroot/yacysearch.java @@ -179,7 +179,7 @@ public class yacysearch { if (cds.equals("app")) contentdom = plasmaSearchQuery.CONTENTDOM_APP; // patch until better search profiles are available - if ((contentdom != plasmaSearchQuery.CONTENTDOM_TEXT) && (count <= 10)) count = 50; + if ((contentdom != plasmaSearchQuery.CONTENTDOM_TEXT) && (count <= 10)) count = 30; serverObjects prop = new serverObjects(); if (post.get("cat", "href").equals("href")) { @@ -294,7 +294,7 @@ public class yacysearch { prop.put("num-results", 1); // no results } } else { - final int totalcount = Integer.parseInt(prop.get("num-results_totalcount", "0")); + final int totalcount = prop.getInt("num-results_totalcount", 0); if (totalcount >= 10) { final Object[] references = (Object[]) prop.get( "references", new String[0]); prop.put("num-results", 4); @@ -363,7 +363,8 @@ public class yacysearch { } } - prop.put("type", (thisSearch.contentdom == plasmaSearchQuery.CONTENTDOM_TEXT) ? 0 : 1); + prop.put("type", (thisSearch.contentdom == plasmaSearchQuery.CONTENTDOM_TEXT) ? 0 : ((thisSearch.contentdom == plasmaSearchQuery.CONTENTDOM_IMAGE) ? 2 : 1)); + if (prop.getInt("type", 0) == 1) prop.put("type_mediatype", cds); prop.put("cat", "href"); prop.put("depth", "0"); diff --git a/source/de/anomic/plasma/plasmaSwitchboard.java b/source/de/anomic/plasma/plasmaSwitchboard.java index 85c1f5590..5cf7e82fd 100644 --- a/source/de/anomic/plasma/plasmaSwitchboard.java +++ b/source/de/anomic/plasma/plasmaSwitchboard.java @@ -113,7 +113,6 @@ import java.net.MalformedURLException; import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.Hashtable; @@ -2436,7 +2435,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser try { // find a list of DHT-peers - ArrayList seeds = new ArrayList(Arrays.asList(yacyCore.dhtAgent.getDHTTargets(log, peerCount, 10, dhtChunk.firstContainer().getWordHash(), dhtChunk.lastContainer().getWordHash(), 0.4))); + ArrayList seeds = yacyCore.dhtAgent.getDHTTargets(log, peerCount, 10, dhtChunk.firstContainer().getWordHash(), dhtChunk.lastContainer().getWordHash(), 0.4); if (seeds.size() < peerCount) { log.logWarning("found not enough (" + seeds.size() + ") peers for distribution"); return false; diff --git a/source/de/anomic/yacy/yacyDHTAction.java b/source/de/anomic/yacy/yacyDHTAction.java index 7a5482c06..8fa41964b 100644 --- a/source/de/anomic/yacy/yacyDHTAction.java +++ b/source/de/anomic/yacy/yacyDHTAction.java @@ -43,8 +43,10 @@ package de.anomic.yacy; +import java.util.ArrayList; import java.util.Enumeration; +import de.anomic.kelondro.kelondroBase64Order; import de.anomic.kelondro.kelondroException; import de.anomic.kelondro.kelondroMScoreCluster; import de.anomic.server.logging.serverLog; @@ -249,7 +251,7 @@ public class yacyDHTAction implements yacyPeerAction { if (d > 0) { return d; // case where the word is 'before' the peer } else { - return 1 + d; // wrap-around case + return ((double) 1) + d; // wrap-around case } } @@ -258,49 +260,37 @@ public class yacyDHTAction implements yacyPeerAction { // the maximum distance between two hashes is 1, the minimum -1 // this can be used like "from - to" // the result is positive if from > to - if ((from == null) || (to == null) || - (from.length() == 0) || (to.length() == 0) || - (from.length() != to.length())) return (double) 0.0; - return hashDistance(from.charAt(0), to.charAt(0)) + hashDistance(from.substring(1), to.substring(1)) / maxAtomarDistance; + assert (from != null); + assert (to != null); + assert (from.length() == 12); + assert (to.length() == 12); + return ((double) (kelondroBase64Order.enhancedCoder.cardinal(from.getBytes()) - kelondroBase64Order.enhancedCoder.cardinal(to.getBytes()))) / ((double) Long.MAX_VALUE); } - private static final double maxAtomarDistance = (double) (1+ ((byte) 'z') - ((byte) '-')); - - private static double hashDistance(char from, char to) { - // the distance is a little bit fuzzy, since not all characters are used in a hash. - if (from < to) - return -hashDistance(to, from); - else - return ((double) (((byte) from) - ((byte) to))) / maxAtomarDistance; - } - - public synchronized yacySeed[] getDHTTargets(serverLog log, int primaryPeerCount, int reservePeerCount, String firstKey, String lastKey, double maxDist) { + public synchronized ArrayList /* of yacySeed */ getDHTTargets(serverLog log, int primaryPeerCount, int reservePeerCount, String firstKey, String lastKey, double maxDist) { // find a list of DHT-peers - yacySeed[] seeds = new yacySeed[primaryPeerCount + reservePeerCount]; - int hc0 = 0; + assert + !(kelondroBase64Order.enhancedCoder.cardinal(firstKey.getBytes()) < kelondroBase64Order.enhancedCoder.cardinal(yacyCore.seedDB.mySeed.hash.getBytes()) && + kelondroBase64Order.enhancedCoder.cardinal(lastKey.getBytes()) > kelondroBase64Order.enhancedCoder.cardinal(yacyCore.seedDB.mySeed.hash.getBytes())); + ArrayList seeds = new ArrayList(); + yacySeed seed; double ownDistance = Math.min(yacyDHTAction.dhtDistance(yacyCore.seedDB.mySeed.hash, firstKey), yacyDHTAction.dhtDistance(yacyCore.seedDB.mySeed.hash, lastKey)); double maxDistance = Math.min(ownDistance, maxDist); double avdist; Enumeration e = this.getAcceptRemoteIndexSeeds(lastKey); - while ((e.hasMoreElements()) && (hc0 < seeds.length)) { - seeds[hc0] = (yacySeed) e.nextElement(); - if (seeds[hc0] != null) { - avdist = Math.max(yacyDHTAction.dhtDistance(seeds[hc0].hash, firstKey), yacyDHTAction.dhtDistance(seeds[hc0].hash, lastKey)); + while ((e.hasMoreElements()) && (seeds.size() < (primaryPeerCount + reservePeerCount))) { + seed = (yacySeed) e.nextElement(); + if (seeds != null) { + avdist = Math.max(yacyDHTAction.dhtDistance(seed.hash, firstKey), yacyDHTAction.dhtDistance(seed.hash, lastKey)); if (avdist < maxDistance) { - if (log != null) log.logInfo("Selected " + ((hc0 < primaryPeerCount) ? "primary" : "reserve") + " DHT target peer " + seeds[hc0].getName() + ":" + seeds[hc0].hash + ", distance = " + avdist); - hc0++; + if (log != null) log.logInfo("Selected " + ((seeds.size() < primaryPeerCount) ? "primary" : "reserve") + " DHT target peer " + seed.getName() + ":" + seed.hash + ", distance = " + avdist); + seeds.add(seed); } } } e = null; // finish enumeration - if (hc0 == seeds.length) { - return seeds; - } else { - yacySeed[] s = new yacySeed[hc0]; - System.arraycopy(seeds, 0, s, 0, hc0); - return s; - } + return seeds; } }