enhanced snippet computation and test method in ViewFile

pull/1/head
Michael Peter Christen 10 years ago
parent 6c10b59f3e
commit c115f3869c

@ -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);

@ -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);

@ -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 {

@ -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);

Loading…
Cancel
Save