diff --git a/htroot/yacysearchitem.java b/htroot/yacysearchitem.java index 0503b9e1a..db1fef978 100644 --- a/htroot/yacysearchitem.java +++ b/htroot/yacysearchitem.java @@ -205,14 +205,12 @@ public class yacysearchitem { final ArrayList media = result.mediaSnippets(); if (item == 0) col = true; if (media != null) { - MediaSnippet ms; int c = 0; - for (int i = 0; i < media.size(); i++) { - ms = media.get(i); - prop.putHTML("content_items_" + i + "_href", ms.href.toNormalform(true, false)); - prop.putHTML("content_items_" + i + "_hrefshort", nxTools.shortenURLString(ms.href.toNormalform(true, false), urllength)); - prop.putHTML("content_items_" + i + "_name", shorten(ms.name, namelength)); - prop.put("content_items_" + i + "_col", (col) ? "0" : "1"); + for (MediaSnippet ms : media) { + prop.putHTML("content_items_" + c + "_href", ms.href.toNormalform(true, false)); + prop.putHTML("content_items_" + c + "_hrefshort", nxTools.shortenURLString(ms.href.toNormalform(true, false), urllength)); + prop.putHTML("content_items_" + c + "_name", shorten(ms.name, namelength)); + prop.put("content_items_" + c + "_col", (col) ? "0" : "1"); c++; col = !col; } diff --git a/source/de/anomic/search/ResultFetcher.java b/source/de/anomic/search/ResultFetcher.java index 5703f7dfd..8c6070eb8 100644 --- a/source/de/anomic/search/ResultFetcher.java +++ b/source/de/anomic/search/ResultFetcher.java @@ -281,7 +281,7 @@ public class ResultFetcher { // check if we already retrieved this item // (happens if a search pages is accessed a second time) EventTracker.update("SEARCH", new ProfilingGraph.searchEvent(query.id(true), "obtain one result entry - start", 0, 0), false, 30000, ProfilingGraph.maxTime); - if (this.result.sizeStore() > item) { + if (this.result.size() > item) { // we have the wanted result already in the result array .. return that return this.result.element(item).element; } @@ -319,32 +319,38 @@ public class ResultFetcher { } public MediaSnippet oneImage(final int item) { - // check if we already retrieved this item (happens if a search pages is accessed a second time) - if (this.images.sizeStore() > item) { - // we have the wanted result already in the result array .. return that - return this.images.element(item).element; - } + // always look for a next object if there are way too less + if (this.images.size() <= item + 10) fillImagesCache(); + + // check if we already retrieved the item + if (this.images.size() > item) return this.images.element(item).element; - // generate result object - final ResultEntry result = nextResult(); - MediaSnippet ms; - if (result != null) { - // iterate over all images in the result - final ArrayList imagemedia = result.mediaSnippets(); - if (imagemedia != null) { - for (int j = 0; j < imagemedia.size(); j++) { - ms = imagemedia.get(j); - images.push(ms, Long.valueOf(ms.ranking)); - //System.out.println("*** image " + ms.href.hash() + " images.size = " + images.size() + "/" + images.size()); - } - } - } + // look again if there are not enough for presentation + while (this.images.size() <= item) { + if (fillImagesCache() == 0) break; + } + if (this.images.size() <= item) return null; // now take the specific item from the image stack - if (this.images.size() <= item) return null; return this.images.element(item).element; } + private int fillImagesCache() { + ResultEntry result = nextResult(); + int c = 0; + if (result == null) return c; + // iterate over all images in the result + final ArrayList imagemedia = result.mediaSnippets(); + if (imagemedia != null) { + for (MediaSnippet ms: imagemedia) { + images.push(ms, Long.valueOf(ms.ranking)); + c++; + System.out.println("*** image " + new String(ms.href.hash()) + " images.size = " + images.size() + "/" + images.size()); + } + } + return c; + } + public ArrayList.stackElement> completeResults(final long waitingtime) { final long timeout = System.currentTimeMillis() + waitingtime; while ((result.size() < query.neededResults()) && (anyWorkerAlive()) && (System.currentTimeMillis() < timeout)) { diff --git a/source/de/anomic/server/serverCore.java b/source/de/anomic/server/serverCore.java index a151c2428..7a6136ce1 100644 --- a/source/de/anomic/server/serverCore.java +++ b/source/de/anomic/server/serverCore.java @@ -155,6 +155,7 @@ public final class serverCore extends AbstractBusyThread implements BusyThread { try { Thread.sleep(100); } catch (final InterruptedException ex) {} // trying to interrupt session + s.notify(); s.interrupt(); try {Thread.sleep(10);} catch (final InterruptedException ex) {} diff --git a/source/net/yacy/kelondro/util/SortStore.java b/source/net/yacy/kelondro/util/SortStore.java index a320c149d..8c1f31ada 100644 --- a/source/net/yacy/kelondro/util/SortStore.java +++ b/source/net/yacy/kelondro/util/SortStore.java @@ -70,10 +70,6 @@ public class SortStore extends SortStack { public int size() { return super.size() + this.offstack.size(); } - - public int sizeStore() { - return this.offstack.size(); - } public void push(final E element, final Long weight) { if (this.offset.containsKey(element)) return;