From bae3783d3845240d6a7d7b8bf889a8ba9dc1bd4a Mon Sep 17 00:00:00 2001 From: orbiter Date: Sun, 5 Mar 2006 01:11:06 +0000 Subject: [PATCH] added a snippet marking (search words are now bold in snippets) git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1823 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/env/templates/header.template | 1 - htroot/xml/snippet.java | 8 ++-- htroot/yacy/search.java | 8 ++-- .../de/anomic/plasma/plasmaSnippetCache.java | 40 +++++++++++++++++-- .../de/anomic/plasma/plasmaSwitchboard.java | 10 ++--- 5 files changed, 49 insertions(+), 18 deletions(-) diff --git a/htroot/env/templates/header.template b/htroot/env/templates/header.template index df074c6cb..5655be583 100644 --- a/htroot/env/templates/header.template +++ b/htroot/env/templates/header.template @@ -62,7 +62,6 @@   Log   Performance   Connections -   Skins  The Project diff --git a/htroot/xml/snippet.java b/htroot/xml/snippet.java index d76afbfc8..941bb5684 100644 --- a/htroot/xml/snippet.java +++ b/htroot/xml/snippet.java @@ -40,11 +40,11 @@ public class snippet { Set queryHashes = plasmaSearchQuery.words2hashes(query); plasmaSnippetCache.result snippet = switchboard.snippetCache.retrieve(url, queryHashes, true, 260); - prop.put("status",snippet.source); - if (snippet.source < 11) { - prop.put("text", (snippet.line != null)?snippet.line.trim():"unknown"); + prop.put("status",snippet.getSource()); + if (snippet.getSource() < 11) { + prop.put("text", (snippet.exists()) ? snippet.getLineMarked(queryHashes) : "unknown"); } else { - prop.put("text", (snippet.error != null)?snippet.error.trim():"unkown"); + prop.put("text", snippet.getError()); } prop.put("urlHash",plasmaURL.urlHash(url)); diff --git a/htroot/yacy/search.java b/htroot/yacy/search.java index 7746f15a3..11521decf 100644 --- a/htroot/yacy/search.java +++ b/htroot/yacy/search.java @@ -137,13 +137,13 @@ public final class search { while ((acc.hasMoreElements()) && (i < squery.wantedResults)) { urlentry = acc.nextElement(); snippet = sb.snippetCache.retrieve(urlentry.url(), squery.queryHashes, false, 260); - if (snippet.source == plasmaSnippetCache.ERROR_NO_MATCH) { + if (snippet.getSource() == plasmaSnippetCache.ERROR_NO_MATCH) { // suppress line: there is no match in that resource } else { - if (snippet.line == null) { - resource = urlentry.toString(); + if (snippet.exists()) { + resource = urlentry.toString(snippet.getLineRaw()); } else { - resource = urlentry.toString(snippet.line); + resource = urlentry.toString(); } if (resource != null) { links.append("resource").append(i).append("=").append(resource).append(serverCore.crlfString); diff --git a/source/de/anomic/plasma/plasmaSnippetCache.java b/source/de/anomic/plasma/plasmaSnippetCache.java index d59247951..a62db6a3a 100644 --- a/source/de/anomic/plasma/plasmaSnippetCache.java +++ b/source/de/anomic/plasma/plasmaSnippetCache.java @@ -95,16 +95,48 @@ public class plasmaSnippetCache { } public class result { - public String line; - public String error; - public int source; + private String line; + private String error; + private int source; public result(String line, int source, String errortext) { this.line = line; this.source = source; this.error = errortext; } + public boolean exists() { + return line != null; + } public String toString() { - return line; + return (line == null) ? "" : line; + } + public String getLineRaw() { + return (line == null) ? "" : line; + } + public String getError() { + return (error == null) ? "" : error.trim(); + } + public String getLineMarked(Set queryHashes) { + if (line == null) return ""; + if ((queryHashes == null) || (queryHashes.size() == 0)) return line.trim(); + if (line.endsWith(".")) line = line.substring(0, line.length() - 1); + Iterator i = queryHashes.iterator(); + String h; + String[] w = line.split(" "); + while (i.hasNext()) { + h = (String) i.next(); + for (int j = 0; j < w.length; j++) { + if (plasmaWordIndexEntry.word2hash(w[j]).equals(h)) w[j] = "" + w[j] + ""; + } + } + StringBuffer l = new StringBuffer(line.length() + queryHashes.size() * 8); + for (int j = 0; j < w.length; j++) { + l.append(w[j]); + l.append(' '); + } + return l.toString().trim(); + } + public int getSource() { + return source; } } diff --git a/source/de/anomic/plasma/plasmaSwitchboard.java b/source/de/anomic/plasma/plasmaSwitchboard.java index efd56f178..c0fbf32f1 100644 --- a/source/de/anomic/plasma/plasmaSwitchboard.java +++ b/source/de/anomic/plasma/plasmaSwitchboard.java @@ -1855,7 +1855,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser //addScoreForked(ref, gs, urlstring.split("/")); if (urlstring.matches(query.urlMask)) { //.* is default snippet = snippetCache.retrieve(url, query.queryHashes, false, 260); - if (snippet.source == plasmaSnippetCache.ERROR_NO_MATCH) { + if (snippet.getSource() == plasmaSnippetCache.ERROR_NO_MATCH) { // suppress line: there is no match in that resource } else { prop.put("results_" + i + "_delete", "/yacysearch.html?search=" + formerSearch + "&Enter=Search&count=" + query.wantedResults + "&order=" + ranking.orderString() + "&resource=local&time=3&deleteref=" + urlhash + "&urlmaskfilter=.*"); @@ -1869,12 +1869,12 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser prop.put("results_" + i + "_size", Long.toString(urlentry.size())); prop.put("results_" + i + "_words",URLEncoder.encode(query.queryWords.toString(),"UTF-8")); // adding snippet if available - if (snippet.line == null) { + if (snippet.exists()) { + prop.put("results_" + i + "_snippet", 1); + prop.put("results_" + i + "_snippet_text", snippet.getLineMarked(query.queryHashes)); + } else { prop.put("results_" + i + "_snippet", 0); prop.put("results_" + i + "_snippet_text", ""); - } else { - prop.put("results_" + i + "_snippet", 1); - prop.put("results_" + i + "_snippet_text", snippet.line.trim()); } i++; }