Skip to content

Commit

Permalink
added a snippet marking
Browse files Browse the repository at this point in the history
(search words are now bold in snippets)

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1823 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Mar 5, 2006
1 parent bfec519 commit bae3783
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 18 deletions.
1 change: 0 additions & 1 deletion htroot/env/templates/header.template
Expand Up @@ -62,7 +62,6 @@
<tr><td class="MenuItem">&nbsp;<img border="0" src="/env/grafics/lock.gif" align="top">&nbsp;<a href="/ViewLog_p.html" class="MenuItemLink">Log</a></td></tr>
<tr><td class="MenuItem">&nbsp;<img border="0" src="/env/grafics/lock.gif" align="top">&nbsp;<a href="/PerformanceQueues_p.html" class="MenuItemLink">Performance</a></td></tr>
<tr><td class="MenuItem">&nbsp;<img border="0" src="/env/grafics/lock.gif" align="top">&nbsp;<a href="/Connections_p.html" class="MenuItemLink">Connections</a></td></tr>
<tr><td class="MenuItem">&nbsp;<img border="0" src="/env/grafics/lock.gif" align="top">&nbsp;<a href="/Skins_p.html" class="MenuItemLink">Skins</a></td></tr>
<tr><td class="MenuSpacer"></td></tr>

<tr><td class="MenuHeader">&nbsp;The Project</td></tr>
Expand Down
8 changes: 4 additions & 4 deletions htroot/xml/snippet.java
Expand Up @@ -40,11 +40,11 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
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));

Expand Down
8 changes: 4 additions & 4 deletions htroot/yacy/search.java
Expand Up @@ -137,13 +137,13 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
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);
Expand Down
40 changes: 36 additions & 4 deletions source/de/anomic/plasma/plasmaSnippetCache.java
Expand Up @@ -95,16 +95,48 @@ public 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] = "<b>" + w[j] + "</b>";
}
}
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;
}
}

Expand Down
10 changes: 5 additions & 5 deletions source/de/anomic/plasma/plasmaSwitchboard.java
Expand Up @@ -1855,7 +1855,7 @@ public serverObjects searchFromLocal(plasmaSearchQuery query,
//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=.*");
Expand All @@ -1869,12 +1869,12 @@ public serverObjects searchFromLocal(plasmaSearchQuery query,
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++;
}
Expand Down

0 comments on commit bae3783

Please sign in to comment.