Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
Added image license generation for solr image search results when results are generated within yjson result writer. This makes it possible to view images in yacyinteractive from solr.
Michael Peter Christende5804320587
diff --git a/htroot/ViewImage.java b/htroot/ViewImage.javaindex 5203952b7..4dba97075 100644--- a/htroot/ViewImage.java+++ b/htroot/ViewImage.java@@ -38,6 +38,7 @@ import net.yacy.cora.protocol.HeaderFramework;import net.yacy.cora.protocol.RequestHeader;import net.yacy.cora.storage.ConcurrentARC;import net.yacy.crawler.data.CrawlQueues;+import net.yacy.data.URLLicense;import net.yacy.document.ImageParser;import net.yacy.kelondro.data.meta.DigestURI;import net.yacy.kelondro.logging.Log;@@ -80,8 +81,13 @@ public class ViewImage {}if ((url == null) && (urlLicense.length() > 0)) {- url = sb.licensedURLs.releaseLicense(urlLicense);- urlString = (url == null) ? null : url.toNormalform(true);+ urlString = URLLicense.releaseLicense(urlLicense);+ try {+ url = new DigestURI(urlString);+ } catch (final MalformedURLException e1) {+ url = null;+ urlString = null;+ }}if (urlString == null) return null;diff --git a/htroot/js/yacyinteractive.js b/htroot/js/yacyinteractive.jsindex 7c79f5e12..fa75b484f 100644--- a/htroot/js/yacyinteractive.js+++ b/htroot/js/yacyinteractive.js@@ -232,7 +232,7 @@ function resultLine(type, item, linenumber) {if (type == "image") {html += "<div style=\"float:left\">";html += "<a href=\"" + item.link + "\" class=\"thumblink\" onclick=\"return hs.expand(this)\">";- html += "<img src=\"/ViewImage.png?maxwidth=96&maxheight=96&code=" + item.code + "\" alt=\"" + title + "\" />";+ html += "<img src=\"/ViewImage.png?maxwidth=96&maxheight=96&code=" + item.guid + "\" alt=\"" + title + "\" />";//html += "<img src=\"" + item.link + "\" width=\"96\" height=\"96\" alt=\"" + title + "\" />";html += "</a>";var name = title;diff --git a/htroot/yacysearchitem.java b/htroot/yacysearchitem.javaindex 5e80889e3..96dde5ccf 100644--- a/htroot/yacysearchitem.java+++ b/htroot/yacysearchitem.java@@ -36,6 +36,7 @@ import net.yacy.cora.protocol.Domains;import net.yacy.cora.protocol.HeaderFramework;import net.yacy.cora.protocol.RequestHeader;import net.yacy.cora.protocol.RequestHeader.FileType;+import net.yacy.data.URLLicense;import net.yacy.kelondro.data.meta.DigestURI;import net.yacy.kelondro.logging.Log;import net.yacy.kelondro.util.Formatter;@@ -186,7 +187,7 @@ public class yacysearchitem {prop.putHTML("content_target", target);if (faviconURL != null && fileType == FileType.HTML) sb.loader.loadIfNotExistBackground(faviconURL, 1024 * 1024 * 10, null, TextSnippet.snippetMinLoadDelay);- prop.putHTML("content_faviconCode", sb.licensedURLs.aquireLicense(faviconURL)); // acquire license for favicon url loading+ prop.putHTML("content_faviconCode", URLLicense.aquireLicense(faviconURL)); // acquire license for favicon url loadingprop.put("content_urlhash", resulthashString);prop.put("content_ranking", result.ranking);prop.put("content_showMetadata_urlhash", resulthashString);@@ -239,7 +240,7 @@ public class yacysearchitem {EventTracker.update(EventTracker.EClass.SEARCH, new ProfilingGraph.EventSearch(theSearch.query.id(true), SearchEventType.FINALIZATION, "" + item, 0, 0), false);final String ext = resultURL.getFileExtension().toLowerCase();if (ext.equals("png") || ext.equals("jpg") || ext.equals("gif")) {- final String license = sb.licensedURLs.aquireLicense(resultURL);+ final String license = URLLicense.aquireLicense(resultURL);prop.put("content_code", license);} else {prop.put("content_code", "");@@ -268,7 +269,7 @@ public class yacysearchitem {final String resultUrlstring = ms.url().toNormalform(true);final String target = sb.getConfig(resultUrlstring.matches(target_special_pattern) ? SwitchboardConstants.SEARCH_TARGET_SPECIAL : SwitchboardConstants.SEARCH_TARGET_DEFAULT, "_self");- final String license = sb.licensedURLs.aquireLicense(ms.url());+ final String license = URLLicense.aquireLicense(ms.url());sb.loader.loadIfNotExistBackground(ms.url(), 1024 * 1024 * 10, null, TextSnippet.snippetMinLoadDelay);prop.putHTML("content_item_hrefCache", (auth) ? "/ViewImage.png?url=" + resultUrlstring : resultUrlstring);prop.putHTML("content_item_href", resultUrlstring);diff --git a/source/net/yacy/cora/document/MultiProtocolURI.java b/source/net/yacy/cora/document/MultiProtocolURI.javaindex e32e87976..979637254 100644--- a/source/net/yacy/cora/document/MultiProtocolURI.java+++ b/source/net/yacy/cora/document/MultiProtocolURI.java@@ -972,6 +972,11 @@ public class MultiProtocolURI implements Serializable, Comparable<MultiProtocolUls.indexOf(".exe",0) >= 0;}+ public final boolean isImage() {+ final String ext = getFileExtension().toLowerCase();+ return "png.gif.jpg.jpeg".indexOf(ext) >= 0;+ }+public final boolean isIndividual() {final String q = unescape(this.path.toLowerCase());for (final String sid: sessionIDnames.keySet()) {diff --git a/source/net/yacy/cora/federate/solr/responsewriter/JsonResponseWriter.java b/source/net/yacy/cora/federate/solr/responsewriter/JsonResponseWriter.javaindex bc98e43fe..7e8cdebc1 100644--- a/source/net/yacy/cora/federate/solr/responsewriter/JsonResponseWriter.java+++ b/source/net/yacy/cora/federate/solr/responsewriter/JsonResponseWriter.java@@ -33,6 +33,7 @@ import net.yacy.cora.document.MultiProtocolURI;import net.yacy.cora.federate.solr.YaCySchema;import net.yacy.cora.federate.solr.responsewriter.OpensearchResponseWriter.ResHead;import net.yacy.cora.protocol.HeaderFramework;+import net.yacy.data.URLLicense;import net.yacy.server.serverObjects;import org.apache.lucene.document.Document;@@ -119,7 +120,6 @@ public class JsonResponseWriter implements QueryResponseWriter {final int responseCount = response.size();SolrIndexSearcher searcher = request.getSearcher();DocIterator iterator = response.iterator();- String urlhash = null;for (int i = 0; i < responseCount; i++) {writer.write("{\n".toCharArray());int id = iterator.nextDoc();@@ -128,6 +128,7 @@ public class JsonResponseWriter implements QueryResponseWriter {int fieldc = fields.size();List<String> texts = new ArrayList<String>();MultiProtocolURI url = null;+ String urlhash = null;String description = "", title = "";StringBuilder path = new StringBuilder(80);for (int j = 0; j < fieldc; j++) {@@ -198,6 +199,9 @@ public class JsonResponseWriter implements QueryResponseWriter {//missing: "code","faviconCode"}+ // get image license+ if (url.isImage()) URLLicense.aquireLicense(urlhash, url.toNormalform(true));+// compute snippet from textssolitaireTag(writer, "path", path.toString());solitaireTag(writer, "title", title.length() == 0 ? (texts.size() == 0 ? path.toString() : texts.get(0)) : title);diff --git a/source/net/yacy/data/URLLicense.java b/source/net/yacy/data/URLLicense.javaindex 586b91fc1..c63c2aeca 100644--- a/source/net/yacy/data/URLLicense.java+++ b/source/net/yacy/data/URLLicense.java@@ -26,11 +26,11 @@package net.yacy.data;-import java.util.Queue;-import java.util.Random;-import java.util.concurrent.ConcurrentHashMap;-import java.util.concurrent.LinkedBlockingQueue;+import java.util.Collections;+import java.util.Map;+import net.yacy.cora.document.ASCII;+import net.yacy.cora.storage.SizeLimitedMap;import net.yacy.kelondro.data.meta.DigestURI;@@ -38,49 +38,27 @@ public class URLLicense {// this class defines a license-generation for URLs// it is used in case of snippet- and preview-Image-fetching to grant also non-authorized users the usage of a image-fetcher servlet- private static final int maxQueue = 500;- private static final long minCheck = 5000;+ private static final int maxQueue = 10000;+ private static final Map<String, String> permissions = Collections.synchronizedMap(new SizeLimitedMap<String, String>(maxQueue));- private final Random random;- private final ConcurrentHashMap<String, DigestURI> permissions;- private final Queue<String> aging;- private long lastCheck;- private final int keylen;-- public URLLicense(final int keylen) {- this.permissions = new ConcurrentHashMap<String, DigestURI>();- this.aging = new LinkedBlockingQueue<String>();- this.lastCheck = System.currentTimeMillis();- this.random = new Random(System.currentTimeMillis());- this.keylen = keylen;+ public static String aquireLicense(final DigestURI url) {+ // generate license key+ String license = ASCII.String(url.hash());+ // store reference to url with license key+ permissions.put(license, url.toNormalform(true));+ // return the license key+ return license;}- public String aquireLicense(final DigestURI url) {- // generate license key- StringBuilder stringBuilder = new StringBuilder(this.keylen * 2);- if (url == null) return stringBuilder.toString();- while (stringBuilder.length() < this.keylen) stringBuilder.append(Integer.toHexString(this.random.nextInt()));- String license = stringBuilder.substring(0, this.keylen);+ public static String aquireLicense(final String license, final String url) {// store reference to url with license key- this.permissions.put(license, url);- this.aging.add(license);- if (System.currentTimeMillis() - this.lastCheck > minCheck) {- // check aging- this.lastCheck = System.currentTimeMillis();- String s;- while (this.aging.size() > maxQueue) {- s = this.aging.poll();- if (s != null) this.permissions.remove(s);- }- }+ permissions.put(license, url);// return the license keyreturn license;}- public DigestURI releaseLicense(final String license) {- DigestURI url = null;- url = this.permissions.remove(license);- return url;+ public static String releaseLicense(final String license) {+ return permissions.remove(license);}}diff --git a/source/net/yacy/search/Switchboard.java b/source/net/yacy/search/Switchboard.javaindex 1bfc4abfd..b3177d69a 100644--- a/source/net/yacy/search/Switchboard.java+++ b/source/net/yacy/search/Switchboard.java@@ -140,7 +140,6 @@ import net.yacy.data.BookmarkHelper;import net.yacy.data.BookmarksDB;import net.yacy.data.ListManager;import net.yacy.data.MessageBoard;-import net.yacy.data.URLLicense;import net.yacy.data.UserDB;import net.yacy.data.WorkTables;import net.yacy.data.wiki.WikiBoard;@@ -260,7 +259,6 @@ public final class Switchboard extends serverSwitch {public int searchQueriesRobinsonFromRemote = 0; // absolute counter of all local queries submitted on this peer from a remote IP without authenticationpublic float searchQueriesGlobal = 0f; // partial counter of remote queries (1/number-of-requested-peers)public SortedMap<byte[], String> clusterhashes; // map of peerhash(String)/alternative-local-address as ip:port or only ip (String) or null if address in seed should be used- public URLLicense licensedURLs;public List<Pattern> networkWhitelist, networkBlacklist;public FilterEngine domainList;private Dispatcher dhtDispatcher;@@ -1179,9 +1177,6 @@ public final class Switchboard extends serverSwitch {Log.logException(e1);}- // initiate url license object- this.licensedURLs = new URLLicense(8);-// set white/blackliststhis.networkWhitelist = Domains.makePatterns(getConfig(SwitchboardConstants.NETWORK_WHITELIST, ""));this.networkBlacklist = Domains.makePatterns(getConfig(SwitchboardConstants.NETWORK_BLACKLIST, ""));