Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
added json and rss output for image search
orbiter969123385b13
diff --git a/htroot/yacysearch.rss b/htroot/yacysearch.rssindex 7af4b92ee..e9884e8e5 100644--- a/htroot/yacysearch.rss+++ b/htroot/yacysearch.rss@@ -3,7 +3,8 @@<rss version="2.0"xmlns:yacy="http://www.yacy.net/"xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"- xmlns:atom="http://www.w3.org/2005/Atom">+ xmlns:media="http://search.yahoo.com/mrss/"+ xmlns:atom="http://www.w3.org/2005/Atom"><!-- YaCy Search Engine; http://yacy.net --><channel><title>#[promoteSearchPageGreeting]#</title>diff --git a/htroot/yacysearchitem.html b/htroot/yacysearchitem.htmlindex 50f20a5d2..a823f3c93 100644--- a/htroot/yacysearchitem.html+++ b/htroot/yacysearchitem.html@@ -20,8 +20,7 @@<p class="urlinfo">#[date]# | #[sizename]# | YBR-#[ybr]# | <a href="ViewFile.html?urlHash=#[urlhash]#&words=#[words]#&display=#[display]#">Info</a> | <a href="yacysearch.html?cat=image&url=#[link]#&search=#[former]#&display=#[display]#">Pictures</a></p></div>::- #{items}#- <div class="thumbcontainer">+ #(item)#::<div class="thumbcontainer"><a href="#[hrefCache]#" class="thumblink" onclick="return hs.expand(this)"><img src="/ViewImage.png?maxwidth=96&maxheight=96&code=#[code]#" alt="#[name]#" /></a>@@ -29,8 +28,7 @@<!--<div class="TableCellDark"><a href="#[href]#">#[name]#</a><br \>#[attr]#</div>-->- </div>- #{/items}#+ </div>#(/item)#::#{items}#<tr class="#(col)#TableCellLight::TableCellDark#(/col)#"><td>#[name]#</td><td><a href="#[href]#">#[hrefshort]#</a></tr>diff --git a/htroot/yacysearchitem.java b/htroot/yacysearchitem.javaindex 5aefe32c0..3b278d77e 100644--- a/htroot/yacysearchitem.java+++ b/htroot/yacysearchitem.java@@ -163,16 +163,22 @@ public class yacysearchitem {prop.put("content", theQuery.contentdom.getCode() + 1); // switch on specific contentfinal MediaSnippet ms = theSearch.result().oneImage(item);if (ms == null) {- prop.put("content_items", "0");+ prop.put("content_item", "0");} else {- prop.putHTML("content_items_0_hrefCache", (auth) ? "/ViewImage.png?url=" + ms.href.toNormalform(true, false) : ms.href.toNormalform(true, false));- prop.putHTML("content_items_0_href", ms.href.toNormalform(true, false));- prop.put("content_items_0_code", sb.licensedURLs.aquireLicense(ms.href));- prop.putHTML("content_items_0_name", shorten(ms.name, namelength));- prop.put("content_items_0_attr", (ms.attr.equals("-1 x -1")) ? "" : "(" + ms.attr + ")"); // attributes, here: original size of image- prop.put("content_items_0_source", ms.source.toNormalform(true, false));- prop.put("content_items_0_sourcedom", ms.source.getHost());- prop.put("content_items", 1);+ prop.putHTML("content_item_hrefCache", (auth) ? "/ViewImage.png?url=" + ms.href.toNormalform(true, false) : ms.href.toNormalform(true, false));+ prop.putHTML("content_item_href", ms.href.toNormalform(true, false));+ prop.put("content_item_code", sb.licensedURLs.aquireLicense(ms.href));+ prop.putHTML("content_item_name", shorten(ms.name, namelength));+ prop.put("content_item_mime", ms.mime);+ prop.put("content_item_fileSize", ms.fileSize);+ prop.put("content_item_width", ms.width);+ prop.put("content_item_height", ms.height);+ prop.put("content_item_attr", (ms.attr.equals("-1 x -1")) ? "" : "(" + ms.attr + ")"); // attributes, here: original size of image+ prop.put("content_item_urlhash", ms.source.hash());+ prop.put("content_item_source", ms.source.toNormalform(true, false));+ prop.put("content_item_sourcedom", ms.source.getHost());+ prop.put("content_item_nl", (item == 0) ? 0 : 1);+ prop.put("content_item", 1);}return prop;}diff --git a/htroot/yacysearchitem.json b/htroot/yacysearchitem.jsonindex fcc58b480..61a663bbb 100644--- a/htroot/yacysearchitem.json+++ b/htroot/yacysearchitem.json@@ -11,15 +11,18 @@"host": "#[host]#","path": "#[path]#","file": "#[file]#"- }::#{items}##(nl)#:: ,#(/nl)#+ }::#(item)#::#(nl)#:: ,#(/nl)#{"title": "#[name]#","icon": "/ViewImage.png?maxwidth=96&maxheight=96&code=#[code]#","image": "#[href]#","cache": "#[hrefCache]#",- "link": "#[source]#",- "host": "#[sourcedom]#"- }#{/items}#::+ "url": "#[source]#",+ "urlhash": "#[urlhash]#",+ "host": "#[sourcedom]#",+ "width": "#[width]#",+ "height": "#[height]#"+ }#(/item)#::::::::diff --git a/htroot/yacysearchitem.xml b/htroot/yacysearchitem.xmlindex b6d022672..863b82342 100644--- a/htroot/yacysearchitem.xml+++ b/htroot/yacysearchitem.xml@@ -9,4 +9,41 @@<yacy:path>#[path]#</yacy:path><yacy:file>#[file]#</yacy:file><guid isPermaLink="false">#[urlhash]#</guid>-</item>#(/content)#\ No newline at end of file+</item>::#(item)#::<item>+<title>#[name]#</title>+<link>#[source]#</link>+<description></description>+<pubDate></pubDate>+<guid isPermaLink="false">#[urlhash]#</guid>+<yacy:host>#[sourcedom]#</yacy:host>+<media:group>+<media:content+ url="#[href]#"+ fileSize="#[fileSize]#"+ type="#[mime]#"+ medium="image"+ isDefault="true"+ expression="full"+ height="#[width]#"+ width="#[height]#" />+<media:content+ url="#[hrefCache]#"+ fileSize="#[fileSize]#"+ type="#[mime]#"+ medium="image"+ isDefault="false"+ expression="full"+ height="#[width]#"+ width="#[height]#" />+<media:content+ url="/ViewImage.png?maxwidth=96&maxheight=96&code=#[code]#"+ fileSize="#[fileSize]#"+ type="#[mime]#"+ medium="image"+ isDefault="false"+ expression="sample"+ height="96"+ width="96" />+</media:group>+</item>#(/item)#::+#(/content)#\ No newline at end of filediff --git a/source/de/anomic/data/MimeTable.java b/source/de/anomic/data/MimeTable.javanew file mode 100644index 000000000..10350eeb3--- /dev/null+++ b/source/de/anomic/data/MimeTable.java@@ -0,0 +1,48 @@+package de.anomic.data;++import java.io.BufferedInputStream;+import java.io.File;+import java.io.FileInputStream;+import java.util.Properties;++import net.yacy.kelondro.data.meta.DigestURI;++public class MimeTable {++ private static final Properties mimeTable = new Properties();++ public static void init(File mimeFile) {+ if (mimeTable.size() == 0) {+ // load the mime table+ BufferedInputStream mimeTableInputStream = null;+ try {+ mimeTableInputStream = new BufferedInputStream(new FileInputStream(mimeFile));+ mimeTable.load(mimeTableInputStream);+ } catch (final Exception e) {+ e.printStackTrace();+ } finally {+ if (mimeTableInputStream != null) try { mimeTableInputStream.close(); } catch (final Exception e1) {}+ }+ }+ }++ public static int size() {+ return mimeTable.size();+ }++ public static String ext2mime(String ext) {+ return mimeTable.getProperty(ext, "application/" + ext);+ }++ public static String ext2mime(String ext, String dfltMime) {+ return mimeTable.getProperty(ext, dfltMime);+ }++ public static String url2mime(DigestURI url, String dfltMime) {+ return ext2mime(url.getFileExtension(), dfltMime);+ }++ public static String url2mime(DigestURI url) {+ return ext2mime(url.getFileExtension());+ }+}diff --git a/source/de/anomic/http/server/HTTPDFileHandler.java b/source/de/anomic/http/server/HTTPDFileHandler.javaindex 3e711e7b9..8942d2cb7 100644--- a/source/de/anomic/http/server/HTTPDFileHandler.java+++ b/source/de/anomic/http/server/HTTPDFileHandler.java@@ -92,6 +92,7 @@ import net.yacy.kelondro.util.FileUtils;import net.yacy.kelondro.util.MemoryControl;import net.yacy.visualization.RasterPlotter;+import de.anomic.data.MimeTable;import de.anomic.http.server.servlets.crawlReceipt;import de.anomic.http.server.servlets.transferURL;import de.anomic.search.Switchboard;@@ -107,7 +108,6 @@ public final class HTTPDFileHandler {private static final boolean safeServletsMode = false; // if true then all servlets are called synchronized- private static final Properties mimeTable = new Properties();// create a class loaderprivate static final serverClassLoader provider = new serverClassLoader(/*this.getClass().getClassLoader()*/);private static serverSwitch switchboard = null;@@ -142,20 +142,11 @@ public final class HTTPDFileHandler {if (switchboard == null) {switchboard = theSwitchboard;- if (mimeTable.size() == 0) {+ if (MimeTable.size() == 0) {// load the mime tablefinal String mimeTablePath = theSwitchboard.getConfig("mimeTable","");- BufferedInputStream mimeTableInputStream = null;- try {- Log.logConfig("HTTPDFiles", "Loading mime mapping file " + mimeTablePath);- mimeTableInputStream = new BufferedInputStream(new FileInputStream(new File(theSwitchboard.getRootPath(), mimeTablePath)));- mimeTable.load(mimeTableInputStream);- } catch (final Exception e) {- Log.logSevere("HTTPDFiles", "ERROR: path to configuration file or configuration invalid\n" + e);- System.exit(1);- } finally {- if (mimeTableInputStream != null) try { mimeTableInputStream.close(); } catch (final Exception e1) {}- }+ Log.logConfig("HTTPDFiles", "Loading mime mapping file " + mimeTablePath);+ MimeTable.init(new File(theSwitchboard.getRootPath(), mimeTablePath));}// create default files array@@ -537,7 +528,7 @@ public final class HTTPDFileHandler {// send an image to clienttargetDate = new Date(System.currentTimeMillis());nocache = true;- final String mimeType = mimeTable.getProperty(targetExt, "text/html");+ final String mimeType = MimeTable.ext2mime(targetExt, "text/html");final ByteBuffer result = RasterPlotter.exportImage(yp.getImage(), targetExt);// write the array to the client@@ -551,7 +542,7 @@ public final class HTTPDFileHandler {// send an image to clienttargetDate = new Date(System.currentTimeMillis());nocache = true;- final String mimeType = mimeTable.getProperty(targetExt, "text/html");+ final String mimeType = MimeTable.ext2mime(targetExt, "text/html");// generate an byte array from the generated imageint width = i.getWidth(null); if (width < 0) width = 96; // bad hack@@ -721,7 +712,7 @@ public final class HTTPDFileHandler {// we have found a file that can be written to the client// if this file uses templates, then we use the template// re-write - method to create an result- String mimeType = mimeTable.getProperty(targetExt,"text/html");+ String mimeType = MimeTable.ext2mime(targetExt, "text/html");final boolean zipContent = requestHeader.acceptGzip() && HTTPDemon.shallTransportZipped("." + conProp.getProperty("EXT",""));if (path.endsWith("html") ||path.endsWith("htm") ||diff --git a/source/de/anomic/search/MediaSnippet.java b/source/de/anomic/search/MediaSnippet.javaindex 64ab6f781..4b482399d 100644--- a/source/de/anomic/search/MediaSnippet.java+++ b/source/de/anomic/search/MediaSnippet.java@@ -30,6 +30,8 @@ import java.util.Iterator;import java.util.Map;import java.util.TreeSet;+import de.anomic.data.MimeTable;+import net.yacy.document.Document;import net.yacy.document.parser.html.ImageEntry;import net.yacy.kelondro.data.meta.DigestURI;@@ -41,15 +43,40 @@ import net.yacy.repository.LoaderDispatcher;public class MediaSnippet implements Comparable<MediaSnippet>, Comparator<MediaSnippet> {public ContentDomain type;public DigestURI href, source;- public String name, attr;+ public String name, attr, mime;public int ranking;+ public int width, height;+ public long fileSize;- public MediaSnippet(final ContentDomain type, final DigestURI href, final String name, final String attr, final int ranking, final DigestURI source) {+ public MediaSnippet(final ContentDomain type, final DigestURI href, final String mime, final String name, final long fileSize, final String attr, final int ranking, final DigestURI source) {this.type = type;this.href = href;+ this.mime = mime;+ this.fileSize = fileSize;this.source = source; // the web page where the media resource appearedthis.name = name;this.attr = attr;+ this.width = -1;+ this.height = -1;+ int p = 0;+ if ((p = attr.indexOf(" x ")) > 0) {+ this.width = Integer.parseInt(attr.substring(0, p).trim());+ this.height = Integer.parseInt(attr.substring(p + 3).trim());+ }+ this.ranking = ranking; // the smaller the better! small values should be shown first+ if ((this.name == null) || (this.name.length() == 0)) this.name = "_";+ if ((this.attr == null) || (this.attr.length() == 0)) this.attr = "_";+ }++ public MediaSnippet(final ContentDomain type, final DigestURI href, final String mime, final String name, final long fileSize, final int width, final int height, final int ranking, final DigestURI source) {+ this.type = type;+ this.href = href;+ this.fileSize = fileSize;+ this.source = source; // the web page where the media resource appeared+ this.name = name;+ this.attr = width + " x " + height;+ this.width = width;+ this.height = height;this.ranking = ranking; // the smaller the better! small values should be shown firstif ((this.name == null) || (this.name.length() == 0)) this.name = "_";if ((this.attr == null) || (this.attr.length() == 0)) this.attr = "_";@@ -115,10 +142,10 @@ public class MediaSnippet implements Comparable<MediaSnippet>, Comparator<MediaSentry = i.next();url = entry.getKey();desc = entry.getValue();- int ranking = TextSnippet.removeAppearanceHashes(url.toNormalform(false, false), queryhashes).size() ++ int ranking = TextSnippet.removeAppearanceHashes(url.toNormalform(false, false), queryhashes).size() +TextSnippet.removeAppearanceHashes(desc, queryhashes).size();if (ranking < 2 * queryhashes.size()) {- result.add(new MediaSnippet(mediatype, url, desc, null, ranking, document.dc_source()));+ result.add(new MediaSnippet(mediatype, url, MimeTable.url2mime(url), desc, document.getTextLength(), null, ranking, document.dc_source()));}}return result;@@ -146,8 +173,8 @@ public class MediaSnippet implements Comparable<MediaSnippet>, Comparator<MediaSint appcount = queryhashes.size() * 2 -TextSnippet.removeAppearanceHashes(url.toNormalform(false, false), queryhashes).size() -TextSnippet.removeAppearanceHashes(desc, queryhashes).size();- final int ranking = Integer.MAX_VALUE - (ientry.height() + 1) * (ientry.width() + 1) * (appcount + 1);- result.add(new MediaSnippet(ContentDomain.IMAGE, url, desc, ientry.width() + " x " + ientry.height(), ranking, document.dc_source()));+ final int ranking = Integer.MAX_VALUE - (ientry.height() + 1) * (ientry.width() + 1) * (appcount + 1);+ result.add(new MediaSnippet(ContentDomain.IMAGE, url, MimeTable.url2mime(url), desc, ientry.fileSize(), ientry.width(), ientry.height(), ranking, document.dc_source()));}return result;}diff --git a/source/net/yacy/document/Document.java b/source/net/yacy/document/Document.javaindex 206c4c8d6..c5fedc7f6 100644--- a/source/net/yacy/document/Document.java+++ b/source/net/yacy/document/Document.java@@ -386,7 +386,7 @@ dc_rightsif (Classification.isMediaExtension(ext)) {// this is not a normal anchor, its a media linkif (Classification.isImageExtension(ext)) {- ContentScraper.addImage(collectedImages, new ImageEntry(url, entry.getValue(), -1, -1));+ ContentScraper.addImage(collectedImages, new ImageEntry(url, entry.getValue(), -1, -1, -1));}else if (Classification.isAudioExtension(ext)) audiolinks.put(url, entry.getValue());else if (Classification.isVideoExtension(ext)) videolinks.put(url, entry.getValue());diff --git a/source/net/yacy/document/parser/html/ContentScraper.java b/source/net/yacy/document/parser/html/ContentScraper.javaindex b6b5ea1a4..e0fe109d1 100644--- a/source/net/yacy/document/parser/html/ContentScraper.java+++ b/source/net/yacy/document/parser/html/ContentScraper.java@@ -148,7 +148,7 @@ public class ContentScraper extends AbstractScraper implements Scraper {final float ratio = (float) Math.min(width, height) / Math.max(width, height);if (ratio > 0.4) {final DigestURI url = absolutePath(tagopts.getProperty("src", ""));- final ImageEntry ie = new ImageEntry(url, tagopts.getProperty("alt", ""), width, height);+ final ImageEntry ie = new ImageEntry(url, tagopts.getProperty("alt", ""), width, height, -1);addImage(images, ie);}// i think that real pictures have witdth & height tags - thq@@ -190,7 +190,7 @@ public class ContentScraper extends AbstractScraper implements Scraper {final String linktitle = tagopts.getProperty("title", "");if (type.equalsIgnoreCase("shortcut icon")) {- final ImageEntry ie = new ImageEntry(newLink, linktitle, -1,-1);+ final ImageEntry ie = new ImageEntry(newLink, linktitle, -1, -1, -1);images.put(ie.url().hash(), ie);this.favicon = newLink;} else if (!type.equalsIgnoreCase("stylesheet") && !type.equalsIgnoreCase("alternate stylesheet")) {@@ -225,7 +225,7 @@ public class ContentScraper extends AbstractScraper implements Scraper {final String type = (p < 0) ? "" : f.substring(p + 1);if (type.equals("png") || type.equals("gif") || type.equals("jpg") || type.equals("jpeg")) {// special handling of such urls: put them to the image urls- final ImageEntry ie = new ImageEntry(url, super.stripAll(new String(text)).trim(), -1, -1);+ final ImageEntry ie = new ImageEntry(url, super.stripAll(new String(text)).trim(), -1, -1, -1);addImage(images, ie);} else {anchors.put(url, super.stripAll(new String(text)).trim());diff --git a/source/net/yacy/document/parser/html/ImageEntry.java b/source/net/yacy/document/parser/html/ImageEntry.javaindex 623b44dd6..7aed5ef92 100644--- a/source/net/yacy/document/parser/html/ImageEntry.java+++ b/source/net/yacy/document/parser/html/ImageEntry.java@@ -33,12 +33,14 @@ public class ImageEntry implements Comparable<ImageEntry>, Comparator<ImageEntryprivate final DigestURI url;private final String alt;private final int width, height;-- public ImageEntry(final DigestURI url, final String alt, final int width, final int height) {+ private final long fileSize;++ public ImageEntry(final DigestURI url, final String alt, final int width, final int height, long fileSize) {this.url = url;this.alt = alt;this.width = width;this.height = height;+ this.fileSize = fileSize;}public DigestURI url() {@@ -56,6 +58,10 @@ public class ImageEntry implements Comparable<ImageEntry>, Comparator<ImageEntrypublic int height() {return this.height;}++ public long fileSize() {+ return this.fileSize;+ }@Overridepublic String toString() {diff --git a/source/net/yacy/document/parser/images/bmpParser.java b/source/net/yacy/document/parser/images/bmpParser.javaindex 5d40b222f..1b8d38488 100644--- a/source/net/yacy/document/parser/images/bmpParser.java+++ b/source/net/yacy/document/parser/images/bmpParser.java@@ -131,7 +131,7 @@ public class bmpParser extends AbstractParser implements Idiom {final HashMap<DigestURI, String> anchors = new HashMap<DigestURI, String>();final HashMap<String, ImageEntry> images = new HashMap<String, ImageEntry>();// add this image to the map of images- images.put(sb.toString(), new ImageEntry(location, "", width, height));+ images.put(sb.toString(), new ImageEntry(location, "", width, height, -1));return new Document(location,diff --git a/source/net/yacy/document/parser/images/genericImageParser.java b/source/net/yacy/document/parser/images/genericImageParser.javaindex 43265c549..284f8a90a 100644--- a/source/net/yacy/document/parser/images/genericImageParser.java+++ b/source/net/yacy/document/parser/images/genericImageParser.java@@ -110,7 +110,7 @@ public class genericImageParser extends AbstractParser implements Idiom {final HashMap<DigestURI, String> anchors = new HashMap<DigestURI, String>();final HashMap<String, ImageEntry> images = new HashMap<String, ImageEntry>();// add this image to the map of images- images.put(sb.toString(), new ImageEntry(location, "", width, height));+ images.put(sb.toString(), new ImageEntry(location, "", width, height, -1));return new Document(location,diff --git a/source/net/yacy/document/parser/rssParser.java b/source/net/yacy/document/parser/rssParser.javaindex 01f89839f..23d808dcf 100644--- a/source/net/yacy/document/parser/rssParser.java+++ b/source/net/yacy/document/parser/rssParser.java@@ -105,7 +105,7 @@ public class rssParser extends AbstractParser implements Idiom {if (feed.getImage() != null) {final DigestURI imgURL = new DigestURI(feed.getImage(), null);- images.put(imgURL.hash(), new ImageEntry(imgURL, feedTitle, -1, -1));+ images.put(imgURL.hash(), new ImageEntry(imgURL, feedTitle, -1, -1, -1));}// loop through the feed items