- 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
pull/1/head
orbiter 18 years ago
parent 4e37eb21ab
commit 7ff86d6ba6

@ -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}

@ -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

@ -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<span.length;x++) {
if (span[x].className == 'snippetLoading') {
var url = document.getElementById("url" + span[x].id);
requestMediaSnippet(url,query);
requestMediaSnippet(url,query,mediatype);
}
}
}
function AllImageSnippets() {
var query = document.getElementsByName("former")[0].value;
var span = document.getElementsByTagName("span");
for(var x=0;x<span.length;x++) {
if (span[x].className == 'snippetLoading') {
var url = document.getElementById("url" + span[x].id);
requestImageSnippet(url,query);
}
}
}
@ -29,13 +41,20 @@ function requestTextSnippet(url, query){
request.send(null);
}
function requestMediaSnippet(url, query){
function requestMediaSnippet(url, query, mediatype){
var request=createRequestObject();
request.open('get', '/xml/snippet.xml?url=' + escape(url) + '&remove=true&media=audio&search=' + escape(query),true);
request.open('get', '/xml/snippet.xml?url=' + escape(url) + '&remove=true&media=' + escape(mediatype) + '&search=' + escape(query),true);
request.onreadystatechange = function () {handleMediaState(request)};
request.send(null);
}
function requestImageSnippet(url, query){
var request=createRequestObject();
request.open('get', '/xml/snippet.xml?url=' + escape(url) + '&remove=true&media=image&search=' + escape(query),true);
request.onreadystatechange = function () {handleImageState(request)};
request.send(null);
}
function handleTextState(req) {
if(req.readyState != 4){
return;
@ -110,14 +129,11 @@ function handleMediaState(req) {
linkanchor.appendChild(document.createTextNode(href));
var col1 = document.createElement("td");
var width1 = document.createAttribute("width");
width1.nodeValue = 200;
col1.setAttributeNode(width1);
col1.setAttribute("width", "200");
col1.appendChild(nameanchor);
var col2 = document.createElement("td");
var width2 = document.createAttribute("width");
width2.nodeValue = 500;
col2.setAttributeNode(width2);
col2.setAttribute("width", "500");
col2.appendChild(linkanchor);
var row = document.createElement("tr");
@ -135,6 +151,66 @@ function handleMediaState(req) {
}
}
function handleImageState(req) {
if(req.readyState != 4){
return;
}
var response = req.responseXML;
var urlHash = response.getElementsByTagName("urlHash")[0].firstChild.data;
var links = response.getElementsByTagName("links")[0].firstChild.data;
var span = document.getElementById(urlHash)
removeAllChildren(span);
if (links > 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;
// <a href="#[url]#"><img src="/ViewImage.png?maxwidth=96&amp;maxheight=96&amp;url=#[url]#" /></a><br /><a href="#[url]#">#[name]#</a>
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");

@ -159,12 +159,24 @@ document.searchform.Enter.value = "search again - catch up more links";
<!-- link end -->
#{/results}#
<script type="text/javascript">
AllMediaSnippets();
AllMediaSnippets("#[mediatype]#");
addHover();
</script>
<!-- linklist end -->
::<!-- type 2: image serch: presents image thumbnails -->
<!-- linklist begin -->
#{results}#
<!-- link begin -->
<span class="snippetLoading" id="#[urlhash]#">loading snippet from <a href="#[url]#" id="url#[urlhash]#">#[urlname]#</a></span>
<!-- link end -->
#{/results}#
<script type="text/javascript">
AllImageSnippets();
addHover();
</script>
<!-- linklist end -->
::<!-- type 3: image thumbnail list for one single url -->
<table border="0" cellspacing="16" cellpadding="0">
#{results}#

@ -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");

@ -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;

@ -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;
}
}

Loading…
Cancel
Save