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.
pull/1/head
Michael Peter Christen 12 years ago
parent d3508fa8ff
commit de58043205

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

@ -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&amp;maxheight=96&amp;code=" + item.code + "\" alt=\"" + title + "\" />";
html += "<img src=\"/ViewImage.png?maxwidth=96&amp;maxheight=96&amp;code=" + item.guid + "\" alt=\"" + title + "\" />";
//html += "<img src=\"" + item.link + "\" width=\"96\" height=\"96\" alt=\"" + title + "\" />";
html += "</a>";
var name = title;

@ -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 loading
prop.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);

@ -972,6 +972,11 @@ public class MultiProtocolURI implements Serializable, Comparable<MultiProtocolU
ls.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()) {

@ -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 texts
solitaireTag(writer, "path", path.toString());
solitaireTag(writer, "title", title.length() == 0 ? (texts.size() == 0 ? path.toString() : texts.get(0)) : title);

@ -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 key
return 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);
}
}

@ -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 authentication
public 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/blacklists
this.networkWhitelist = Domains.makePatterns(getConfig(SwitchboardConstants.NETWORK_WHITELIST, ""));
this.networkBlacklist = Domains.makePatterns(getConfig(SwitchboardConstants.NETWORK_BLACKLIST, ""));

Loading…
Cancel
Save