added image search to yacyinteractive.html

this causes that the search result view switches from list format to image preview format when a search is restricted to png, gif or jpg documents

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7358 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent fffb91447a
commit f0651e5f2f

@ -11,6 +11,8 @@ var totalResults = 0;
var filetypes;
var topics;
var script = "";
var modifier = "";
var modifiertype = "";
function search(search) {
query = search;
@ -49,14 +51,23 @@ function preparepage(str) {
topics = navget(firstChannel.navigation, "topics");
filetypes = {};
script = "";
document.getElementById("searchresults").innerHTML = resultList();
if (query.length >= 13 && query.substring(query.length - 13, query.length - 3) == " filetype:") {
modifier = query.substring(query.length - 12);
}
if (modifier != "") modifiertype = modifier.substring(modifier.length - 3)
if (modifiertype == "png" || modifiertype == "gif" || modifiertype == "jpg") {
document.getElementById("searchresults").innerHTML = resultImages();
} else {
document.getElementById("searchresults").innerHTML = resultList();
}
document.getElementById("searchnavigation").innerHTML = resultStart();
hideDownloadScript();
}
function makeDownloadScript() {
document.getElementById("downloadscript").innerHTML = "<div style=\"float:left\"><pre>" + script + "</pre></div>";
document.getElementById("downloadscript").innerHTML = "<div style=\"float:left\"><pre>" + script + "</pre><br/></div>";
document.getElementById("downloadbutton").innerHTML = "<input id=\"downloadbutton\" type=\"button\" value=\"hide the download script\" onClick=\"hideDownloadScript();\"/>";
}
@ -91,8 +102,8 @@ function resultStart() {
html += "<span style=\"display:block\">apply a <b>filter</b> by filetype:&nbsp;&nbsp;&nbsp;&nbsp;" + extnav + "</span>";
} else {
// check if there is a filetype constraint and offer a removal
if (query.length >= 13 && query.substring(query.length - 13, query.length - 3) == " filetype:") {
html += "<span style=\"display:block\"><a style=\"text-decoration:underline\" href=\"/yacyinteractive.html?query=" + query.substring(0, query.length - 12) + "\">remote the filter '" + query.substring(query.length - 12) + "'</a></span>";
if (modifier != "") {
html += "<span style=\"display:block\"><a style=\"text-decoration:underline\" href=\"/yacyinteractive.html?query=" + query.substring(0, query.length - 12) + "\">remove the filter '" + modifier + "'</a></span>";
}
}
@ -113,27 +124,22 @@ function resultStart() {
function resultList() {
var html = "";
if (searchresult.length > 0) {
var item;
html += "<table class=\"sortable\" id=\"sortable\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"99%\">";
html += "<tr class=\"TableHeader\" valign=\"bottom\">";
html += "<td width=\"40\">Protocol</td>";
html += "<td width=\"60\">Host</td>";
html += "<td width=\"260\">Path</td>";
html += "<td width=\"360\">Name</td>";
html += "<td width=\"60\">Size</td>";
//html += "<td>Description</td>";
html += "<td width=\"70\">Date</td></tr>";
for (var i = 0; i < searchresult.length; i++) {
var item = searchresult[i];
html += resultLine(item);
}
html += "<tr class=\"TableHeader\" valign=\"bottom\"><td width=\"40\">Protocol</td><td width=\"60\">Host</td><td width=\"260\">Path</td><td width=\"360\">Name</td><td width=\"60\">Size</td><td width=\"70\">Date</td></tr>";
for (var i = 0; i < searchresult.length; i++) { html += resultLine("row", searchresult[i]); }
html += "</table>";
}
return html;
}
function resultLine(item) {
function resultImages() {
var html = "";
for (var i = 0; i < searchresult.length; i++) { html += resultLine("image", searchresult[i]); }
return html;
}
function resultLine(type, item) {
// evaluate item
p = item.link.indexOf("//");
protocol = "";
host = "";
@ -145,23 +151,14 @@ function resultLine(item) {
path = item.link.substring(q + 1);
}
if (path.length >= 40) path = path.substring(0, 18) + "..." + path.substring(path.length - 19);
html += "<tr class=\"TableCellLight\">";
html += "<td align=\"left\">" + protocol + "</td>";
html += "<td align=\"left\"><a href=\"" + protocol + "://" + host + "/" + "\">" + host + "</a></td>";
html += "<td align=\"left\"><a href=\"" + item.link + "\">" + path + "</a></td>";
title = item.title;
if (title == "") title = path;
if (title.length >= 60) title = title.substring(0, 28) + "..." + title.substring(title.length - 29);
html += "<td align=\"left\"><a href=\"" + item.link + "\">" + title + "</a></td>";
html += "<td align=\"right\">" + item.sizename + "</td>";
//html += "<td>" + item.description + "</td>";
pd = item.pubDate;
if (pd.substring(pd.length - 6) == " +0000") pd = pd.substring(0, pd.length - 6);
if (pd.substring(pd.length - 9) == " 00:00:00") pd = pd.substring(0, pd.length - 9);
if (pd.substring(pd.length - 5) == " 2010") pd = pd.substring(0, pd.length - 5);
html += "<td align=\"right\">" + pd + "</td>";
html += "</tr>";
// update navigation
if (item.link && item.link.length > 4) {
ext = item.link.substring(item.link.length - 4);
@ -178,6 +175,30 @@ function resultLine(item) {
// update download script
script += "curl -OL \"" + item.link + "\"\n";
// return table row
// make table row
var html = "";
if (type == "row") {
html += "<tr class=\"TableCellLight\">";
html += "<td align=\"left\">" + protocol + "</td>";
html += "<td align=\"left\"><a href=\"" + protocol + "://" + host + "/" + "\">" + host + "</a></td>";
html += "<td align=\"left\"><a href=\"" + item.link + "\">" + path + "</a></td>";
html += "<td align=\"left\"><a href=\"" + item.link + "\">" + title + "</a></td>";
html += "<td align=\"right\">" + item.sizename + "</td>";
//html += "<td>" + item.description + "</td>";
html += "<td align=\"right\">" + pd + "</td>";
html += "</tr>";
}
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 += "</a>";
var name = title;
while ((p = name.indexOf("/")) >= 0) { name = name.substring(p + 1); }
html += "<div class=\"highslide-caption\"><a href=\"" + item.link + "\">" + name + "</a><br /><a href=\"" + protocol + "://" + host + "/" + "\">" + host + "</a></div>";
html += "</div>";
}
// return entry
return html;
}

@ -318,7 +318,7 @@ public class yacysearch {
String ft = querystring.substring(filetype + 9, ftb);
querystring = querystring.replace("filetype:" + ft, "");
while (ft.length() > 0 && ft.charAt(0) == '.') ft = ft.substring(1);
if(ft.length() > 0) {
if (ft.length() > 0) {
if (urlmask == null) {
urlmask = ".*\\." + ft;
} else {

@ -104,18 +104,17 @@ public class yacysearchitem {
final ResultEntry result = theSearch.oneResult(item, theQuery.isLocal() ? 1000 : 5000);
if (result == null) return prop; // no content
final int port=result.url().getPort();
DigestURI resultURL = result.url();
final int port = resultURL.getPort();
DigestURI faviconURL = null;
if (isHtml && !sb.isIntranetMode() && !result.url().isLocal()) try {
faviconURL = new DigestURI(result.url().getProtocol() + "://" + result.url().getHost() + ((port != -1) ? (":" + port) : "") + "/favicon.ico");
if (isHtml && !sb.isIntranetMode() && !resultURL.isLocal()) try {
faviconURL = new DigestURI(resultURL.getProtocol() + "://" + resultURL.getHost() + ((port != -1) ? (":" + port) : "") + "/favicon.ico");
} catch (final MalformedURLException e1) {
Log.logException(e1);
faviconURL = null;
}
prop.put("content", 1); // switch on specific content
prop.put("content_authorized", authenticated ? "1" : "0");
prop.put("content_authorized_recommend", (sb.peers.newsPool.getSpecific(yacyNewsPool.OUTGOING_DB, yacyNewsPool.CATEGORY_SURFTIPP_ADD, "url", result.urlstring()) == null) ? "1" : "0");
prop.putHTML("content_authorized_recommend_deletelink", "/yacysearch.html?query=" + theQuery.queryString.replace(' ', '+') + "&Enter=Search&count=" + theQuery.displayResults() + "&offset=" + (theQuery.neededResults() - theQuery.displayResults()) + "&order=" + crypt.simpleEncode(theQuery.ranking.toExternalString()) + "&resource=local&time=3&deleteref=" + new String(result.hash()) + "&urlmaskfilter=.*");
@ -138,9 +137,9 @@ public class yacysearchitem {
//prop.put("content_ybr", RankingProcess.ybr(result.hash()));
prop.putHTML("content_size", Integer.toString(result.filesize())); // we don't use putNUM here because that number shall be usable as sorting key. To print the size, use 'sizename'
prop.putHTML("content_sizename", sizename(result.filesize()));
prop.putHTML("content_host", result.url().getHost() == null ? "" : result.url().getHost());
prop.putHTML("content_file", result.url().getFile());
prop.putHTML("content_path", result.url().getPath());
prop.putHTML("content_host", resultURL.getHost() == null ? "" : resultURL.getHost());
prop.putHTML("content_file", resultURL.getFile());
prop.putHTML("content_path", resultURL.getPath());
prop.put("content_nl", (item == 0) ? 0 : 1);
prop.putHTML("content_publisher", result.publisher());
prop.putHTML("content_creator", result.creator());// author
@ -167,10 +166,18 @@ public class yacysearchitem {
prop.put("content_heuristic_name", heuristic.heuristicName);
}
EventTracker.update(EventTracker.EClass.SEARCH, new ProfilingGraph.searchEvent(theQuery.id(true), SearchEvent.Type.FINALIZATION, "" + item, 0, 0), false);
String ext = resultURL.getFileExtension().toLowerCase();
if (ext.equals("png") || ext.equals("jpg") || ext.equals("gif")) {
String license = sb.licensedURLs.aquireLicense(resultURL);
prop.put("content_code", license);
} else {
prop.put("content_code", "");
}
return prop;
}
if (theQuery.contentdom == ContentDomain.IMAGE) {
// image search; shows thumbnails
@ -179,10 +186,11 @@ public class yacysearchitem {
if (ms == null) {
prop.put("content_item", "0");
} else {
String license = sb.licensedURLs.aquireLicense(ms.href);
sb.loader.loadIfNotExistBackground(ms.href.toNormalform(true, false), 1024 * 1024 * 10);
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.put("content_item_code", license);
prop.putHTML("content_item_name", shorten(ms.name, namelength));
prop.put("content_item_mimetype", ms.mime);
prop.put("content_item_fileSize", ms.fileSize);

@ -2,6 +2,7 @@
{
"title": "#[title-json]#",
"link": "#[link]#",
"code": "#[code]#",
"description": "#[description-json]#",
"pubDate": "#[date822]#",
"size": "#[size]#",

@ -185,7 +185,7 @@ public final class QueryParams {
this.contentdom = contentdom;
this.itemsPerPage = Math.min((specialRights) ? 1000 : 100, itemsPerPage);
this.offset = Math.min((specialRights) ? 10000 : 1000, offset);
this.urlMask = Pattern.compile(urlMask);
this.urlMask = Pattern.compile(urlMask.toLowerCase());
this.urlMask_isCatchall = this.urlMask.toString().equals(catchall_pattern.toString());
this.prefer = Pattern.compile(prefer);
this.prefer_isMatchnothing = this.prefer.toString().equals(matchnothing_pattern.toString());

@ -287,6 +287,7 @@ public final class Condenser {
}
private void createCondensement(final InputStream is, final DidYouMeanLibrary meaningLib) throws UnsupportedEncodingException {
assert is != null;
final Set<String> currsentwords = new HashSet<String>();
StringBuilder sentence = new StringBuilder(100);
String word = "";
@ -513,6 +514,7 @@ public final class Condenser {
private DidYouMeanLibrary meaningLib;
public sievedWordsEnum(final InputStream is, final DidYouMeanLibrary meaningLib) throws UnsupportedEncodingException {
assert is != null;
this.e = new unsievedWordsEnum(is);
this.buffer = nextElement0();
this.meaningLib = meaningLib;
@ -557,6 +559,7 @@ public final class Condenser {
private int sIndex;
public unsievedWordsEnum(final InputStream is) throws UnsupportedEncodingException {
assert is != null;
e = new sentencesFromInputStreamEnum(is);
s = new ArrayList<StringBuilder>();
sIndex = 0;
@ -634,6 +637,7 @@ public final class Condenser {
}
public static sentencesFromInputStreamEnum sentencesFromInputStream(final InputStream is) {
assert is != null;
try {
return new sentencesFromInputStreamEnum(is);
} catch (final UnsupportedEncodingException e) {
@ -651,6 +655,7 @@ public final class Condenser {
private boolean pre = false;
public sentencesFromInputStreamEnum(final InputStream is) throws UnsupportedEncodingException {
assert is != null;
raf = new BufferedReader(new InputStreamReader(is, "UTF-8"));
buffer = nextElement0();
counter = 0;

@ -112,12 +112,7 @@ public class Document {
this.outboundLinks = -1;
this.languages = languages;
this.indexingDenied = indexingDenied;
if (text == null)
this.text = new ByteArrayOutputStream();
else {
this.text = text;
}
this.text = text == null ? new ByteArrayOutputStream() : text;
}
public void setInboundLinks(int il) {

@ -555,8 +555,8 @@ public class URIMetadataRow implements URIMetadata {
this.dc_publisher = publisher;
}
public boolean matches(Pattern matcher) {
if (this.urlRaw != null) return matcher.matcher(this.urlRaw).matches();
if (this.url != null) return matcher.matcher(this.url.toNormalform(true, true)).matches();
if (this.urlRaw != null) return matcher.matcher(this.urlRaw.toLowerCase()).matches();
if (this.url != null) return matcher.matcher(this.url.toNormalform(true, true).toLowerCase()).matches();
return false;
}
public DigestURI url() {

Loading…
Cancel
Save