Apache Nutch is an extensible and scalable web crawler
NUTCH-257 : Fix open search backward compatibility
Jerome Charronf16c8f5e4bbd
diff --git a/src/java/org/apache/nutch/searcher/OpenSearchServlet.java b/src/java/org/apache/nutch/searcher/OpenSearchServlet.javaindex 972b21014..c77e54bd8 100644--- a/src/java/org/apache/nutch/searcher/OpenSearchServlet.java+++ b/src/java/org/apache/nutch/searcher/OpenSearchServlet.java@@ -211,7 +211,7 @@ public class OpenSearchServlet extends HttpServlet {Element item = addNode(doc, channel, "item");addNode(doc, item, "title", title);- addNode(doc, item, "description", summaries[i].toString());+ addNode(doc, item, "description", summaries[i].toHtml(false));addNode(doc, item, "link", url);addNode(doc, item, "nutch", "site", hit.getDedupValue());diff --git a/src/java/org/apache/nutch/searcher/Summary.java b/src/java/org/apache/nutch/searcher/Summary.javaindex c89616aa6..4bb78a9f8 100644--- a/src/java/org/apache/nutch/searcher/Summary.java+++ b/src/java/org/apache/nutch/searcher/Summary.java@@ -102,7 +102,7 @@ public class Summary implements Writable {return (Fragment[])fragments.toArray(FRAGMENT_PROTO);}- /** Returns an String representation of this Summary. */+ /** Returns a String representation of this Summary. */public String toString() {StringBuffer buffer = new StringBuffer();for (int i = 0; i < fragments.size(); i++) {@@ -110,6 +110,36 @@ public class Summary implements Writable {}return buffer.toString();}++ /**+ * Returns a HTML representation of this Summary.+ * HTML output for <b>Highlight</b> fragments is+ * <code><span class="highlight">highlight's text</span></code>,+ * for <b>Ellipsis</b> fragments is+ * <code><span class="highlight"> ... </span></code>, for generic+ * <b>Fragment</b> is simply the fragment's text.<br/>+ *+ * @param encode specifies if the summary's entities should be encoded.+ */+ public String toHtml(boolean encode) {+ Fragment fragment = null;+ StringBuffer buf = new StringBuffer();+ for (int i=0; i<fragments.size(); i++) {+ fragment = (Fragment) fragments.get(i);+ if (fragment.isHighlight()) {+ buf.append("<span class=\"highlight\">")+ .append(encode ? Entities.encode(fragment.getText())+ : fragment.getText())+ .append("</span>");+ } else if (fragment.isEllipsis()) {+ buf.append("<span class=\"ellipsis\"> ... </span>");+ } else {+ buf.append(encode ? Entities.encode(fragment.getText())+ : fragment.getText());+ }+ }+ return buf.toString();+ }// Inherited Javadocpublic boolean equals(Object o) {diff --git a/src/web/jsp/search.jsp b/src/web/jsp/search.jspindex 6ee2c99cc..0cf3da3e2 100644--- a/src/web/jsp/search.jsp+++ b/src/web/jsp/search.jsp@@ -9,7 +9,6 @@import="org.apache.nutch.html.Entities"import="org.apache.nutch.searcher.*"- import="org.apache.nutch.searcher.Summary.Fragment"import="org.apache.nutch.plugin.*"import="org.apache.nutch.clustering.*"import="org.apache.hadoop.conf.*"@@ -212,26 +211,11 @@ out.flush();String title = detail.getValue("title");String url = detail.getValue("url");String id = "idx=" + hit.getIndexNo() + "&id=" + hit.getIndexDocNo();+ String summary = summaries[i].toHtml(true);if (title == null || title.equals("")) { // use url for docs w/o titletitle = url;}-- // Build the summary- StringBuffer sum = new StringBuffer();- Fragment[] fragments = summaries[i].getFragments();- for (int j=0; j<fragments.length; j++) {- if (fragments[j].isHighlight()) {- sum.append("<span class=\"highlight\">")- .append(Entities.encode(fragments[j].getText()))- .append("</span>");- } else if (fragments[j].isEllipsis()) {- sum.append("<span class=\"ellipsis\"> ... </span>");- } else {- sum.append(Entities.encode(fragments[j].getText()));- }- }- String summary = sum.toString();%><b><a href="<%=url%>"><%=Entities.encode(title)%></a></b><%@ include file="more.jsp" %>