From 7f7cbc5019dcaad02f006bbf34933ae80543a7f2 Mon Sep 17 00:00:00 2001 From: orbiter Date: Sun, 3 Jul 2005 13:37:20 +0000 Subject: [PATCH] fixed bug with snippets git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@365 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/plasma/plasmaSnippetCache.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/source/de/anomic/plasma/plasmaSnippetCache.java b/source/de/anomic/plasma/plasmaSnippetCache.java index d5a80dcc3..64fa0dd16 100644 --- a/source/de/anomic/plasma/plasmaSnippetCache.java +++ b/source/de/anomic/plasma/plasmaSnippetCache.java @@ -238,11 +238,14 @@ public class plasmaSnippetCache { hs = hashSentence(result); j = queryhashes.iterator(); Integer pos; + Set remaininghashes = new HashSet(); int p, minpos = result.length(), maxpos = -1; while (j.hasNext()) { - pos = (Integer) hs.get((String) j.next()); - if (pos != null) { - j.remove(); + hash = (String) j.next(); + pos = (Integer) hs.get(hash); + if (pos == null) { + remaininghashes.add(hash); + } else { p = pos.intValue(); if (p > maxpos) maxpos = p; if (p < minpos) minpos = p; @@ -267,7 +270,7 @@ public class plasmaSnippetCache { // so cut it here at both ends at once int newlen = maxpos - minpos + 10; int around = (maxLength - newlen) / 2; - result = "[..] " + result.substring(minpos - around, maxpos + around).trim() + " [..]"; + result = "[..] " + result.substring(minpos - around, ((maxpos + around) > result.length()) ? result.length() : (maxpos + around)).trim() + " [..]"; minpos = around; maxpos = result.length() - around - 5; } @@ -289,7 +292,7 @@ public class plasmaSnippetCache { // and find recursively more sentences maxLength = maxLength - result.length(); if (maxLength < 20) maxLength = 20; - String nextSnippet = computeSnippet(sentences, queryhashes, minLength, maxLength); + String nextSnippet = computeSnippet(sentences, remaininghashes, minLength, maxLength); return result + ((nextSnippet == null) ? "" : (" / " + nextSnippet)); }