Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

enhanced snippet computation and test method in ViewFile

Michael Peter Christenc115f3869c37
diff --git a/htroot/ViewFile.java b/htroot/ViewFile.java
index eea8c3275..cebc8a77e 100644
--- a/htroot/ViewFile.java
+++ b/htroot/ViewFile.java
@@ -56,6 +56,7 @@ import net.yacy.kelondro.data.meta.URIMetadataNode;
import net.yacy.search.Switchboard;
import net.yacy.search.index.Segment;
import net.yacy.search.query.QueryGoal;
+import net.yacy.search.query.SearchEvent;
import net.yacy.search.snippet.TextSnippet;
import net.yacy.server.serverObjects;
import net.yacy.server.serverSwitch;
@@ -168,7 +169,7 @@ public class ViewFile {
}
prop.put("url", url.toNormalform(true));
prop.put("moar", 1);
- prop.put("moar_search", post.get("search",""));
+ prop.putHTML("moar_search", post.get("search",""));
// loading the resource content as byte array
prop.put("error_incache", Cache.has(url.hash()) ? 1 : 0);
@@ -355,19 +356,19 @@ public class ViewFile {
if (showSnippet) {
QueryGoal goal = new QueryGoal(post.get("search", ""));
TextSnippet snippet = new TextSnippet(
- null,
+ sb.loader,
urlEntry,
goal.getIncludeHashes(),
CacheStrategy.CACHEONLY,
false,
- 180,
+ SearchEvent.SNIPPET_MAX_LENGTH,
false);
String titlestr = urlEntry.dc_title();
// if title is empty use filename as title
if (titlestr.isEmpty()) { // if url has no filename, title is still empty (e.g. "www.host.com/" )
titlestr = urlEntry.url() != null ? urlEntry.url().getFileName() : "";
}
- final String desc = (snippet == null) ? "" : snippet.isMarked() ? snippet.getLineRaw() : snippet.getLineMarked(goal);
+ final String desc = (snippet == null) ? "" : snippet.descriptionline(goal);
prop.put("showSnippet_headline", titlestr);
prop.put("showSnippet_teasertext", desc);
prop.put("showSnippet", 1);
diff --git a/htroot/yacysearchitem.java b/htroot/yacysearchitem.java
index 348d1a90c..0e49af506 100644
--- a/htroot/yacysearchitem.java
+++ b/htroot/yacysearchitem.java
@@ -223,7 +223,7 @@ public class yacysearchitem {
prop.putHTML("content_former", origQ);
prop.putHTML("content_showPictures_former", origQ);
final TextSnippet snippet = result.textSnippet();
- final String desc = (snippet == null) ? "" : snippet.isMarked() ? snippet.getLineRaw() : snippet.getLineMarked(theSearch.query.getQueryGoal());
+ final String desc = (snippet == null) ? "" : snippet.descriptionline(theSearch.query.getQueryGoal());
prop.put("content_description", desc);
prop.putXML("content_description-xml", desc);
prop.putJSON("content_description-json", desc);
diff --git a/source/net/yacy/search/query/SearchEvent.java b/source/net/yacy/search/query/SearchEvent.java
index 2349849b6..3d2df34ef 100644
--- a/source/net/yacy/search/query/SearchEvent.java
+++ b/source/net/yacy/search/query/SearchEvent.java
@@ -1239,11 +1239,20 @@ public final class SearchEvent {
Element<URIMetadataNode> localEntryElement = this.nodeStack.sizeQueue() > 0 ? this.nodeStack.poll() : null;
URIMetadataNode node = localEntryElement == null ? null : localEntryElement.getElement();
if (node != null) {
- LinkedHashSet<String> solrsnippet = this.snippets.remove(ASCII.String(node.hash())); // we can remove this because it's used only once
- if (solrsnippet != null && solrsnippet.size() > 0) {
- OpensearchResponseWriter.removeSubsumedTitle(solrsnippet, node.dc_title());
- final TextSnippet snippet = new TextSnippet(node.hash(), OpensearchResponseWriter.getLargestSnippet(solrsnippet), true, ResultClass.SOURCE_CACHE, "");
- ResultEntry re = new ResultEntry(node, this.query.getSegment(), this.peers, snippet, 0);
+ LinkedHashSet<String> solrsnippetlines = this.snippets.remove(ASCII.String(node.hash())); // we can remove this because it's used only once
+ if (solrsnippetlines != null && solrsnippetlines.size() > 0) {
+ OpensearchResponseWriter.removeSubsumedTitle(solrsnippetlines, node.dc_title());
+ final TextSnippet solrsnippet = new TextSnippet(node.hash(), OpensearchResponseWriter.getLargestSnippet(solrsnippetlines), true, ResultClass.SOURCE_CACHE, "");
+ final TextSnippet yacysnippet = new TextSnippet(this.loader,
+ node,
+ this.query.getQueryGoal().getIncludeHashes(),
+ CacheStrategy.CACHEONLY,
+ false,
+ 180,
+ false);
+ final String solrsnippetline = solrsnippet.descriptionline(this.getQuery().getQueryGoal());
+ final String yacysnippetline = yacysnippet.descriptionline(this.getQuery().getQueryGoal());
+ ResultEntry re = new ResultEntry(node, this.query.getSegment(), this.peers, solrsnippetline.length() > yacysnippetline.length() ? solrsnippet : yacysnippet, 0);
addResult(re);
success = true;
} else {
diff --git a/source/net/yacy/search/snippet/TextSnippet.java b/source/net/yacy/search/snippet/TextSnippet.java
index 907440b58..660742ea2 100644
--- a/source/net/yacy/search/snippet/TextSnippet.java
+++ b/source/net/yacy/search/snippet/TextSnippet.java
@@ -405,6 +405,13 @@ public class TextSnippet implements Comparable<TextSnippet>, Comparator<TextSnip
return l.toString().trim();
}
+ private String descriptionline = null;
+ public String descriptionline(QueryGoal queryGoal) {
+ if (descriptionline != null) return descriptionline;
+ descriptionline = this.isMarked() ? this.getLineRaw() : this.getLineMarked(queryGoal);
+ return descriptionline;
+ }
+
@Override
public int compareTo(final TextSnippet o) {
return Base64Order.enhancedCoder.compare(this.urlhash, o.urlhash);