You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nutch.apache.org by je...@apache.org on 2006/05/13 09:43:10 UTC
svn commit: r406035 - in /lucene/nutch/trunk/src:
java/org/apache/nutch/searcher/OpenSearchServlet.java
java/org/apache/nutch/searcher/Summary.java web/jsp/search.jsp
Author: jerome
Date: Sat May 13 00:43:10 2006
New Revision: 406035
URL: http://svn.apache.org/viewcvs?rev=406035&view=rev
Log:
NUTCH-257 : Fix open search backward compatibility
Modified:
lucene/nutch/trunk/src/java/org/apache/nutch/searcher/OpenSearchServlet.java
lucene/nutch/trunk/src/java/org/apache/nutch/searcher/Summary.java
lucene/nutch/trunk/src/web/jsp/search.jsp
Modified: lucene/nutch/trunk/src/java/org/apache/nutch/searcher/OpenSearchServlet.java
URL: http://svn.apache.org/viewcvs/lucene/nutch/trunk/src/java/org/apache/nutch/searcher/OpenSearchServlet.java?rev=406035&r1=406034&r2=406035&view=diff
==============================================================================
--- lucene/nutch/trunk/src/java/org/apache/nutch/searcher/OpenSearchServlet.java (original)
+++ lucene/nutch/trunk/src/java/org/apache/nutch/searcher/OpenSearchServlet.java Sat May 13 00:43:10 2006
@@ -211,7 +211,7 @@
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());
Modified: lucene/nutch/trunk/src/java/org/apache/nutch/searcher/Summary.java
URL: http://svn.apache.org/viewcvs/lucene/nutch/trunk/src/java/org/apache/nutch/searcher/Summary.java?rev=406035&r1=406034&r2=406035&view=diff
==============================================================================
--- lucene/nutch/trunk/src/java/org/apache/nutch/searcher/Summary.java (original)
+++ lucene/nutch/trunk/src/java/org/apache/nutch/searcher/Summary.java Sat May 13 00:43:10 2006
@@ -102,13 +102,43 @@
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++) {
buffer.append(fragments.get(i));
}
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 Javadoc
Modified: lucene/nutch/trunk/src/web/jsp/search.jsp
URL: http://svn.apache.org/viewcvs/lucene/nutch/trunk/src/web/jsp/search.jsp?rev=406035&r1=406034&r2=406035&view=diff
==============================================================================
--- lucene/nutch/trunk/src/web/jsp/search.jsp (original)
+++ lucene/nutch/trunk/src/web/jsp/search.jsp Sat May 13 00:43:10 2006
@@ -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 @@
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 title
title = 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" %>