Attached is a patch for search.jsp adding support for grouping by host.
I'll be adding a "more results from host" link.
In order to do this I'm probably going to revamp the whole search page
by adding functions that run either query logic this should also clean
up the code nicely.
Mike
Index: nutch/src/web/jsp/search.jsp
===================================================================
RCS file: /cvsroot/nutch/nutch/src/web/jsp/search.jsp,v
retrieving revision 1.25
diff -u -3 -p -r1.25 search.jsp
--- nutch/src/web/jsp/search.jsp 19 Jul 2004 17:10:16 -0000 1.25
+++ nutch/src/web/jsp/search.jsp 24 Jul 2004 01:34:39 -0000
@@ -21,6 +21,10 @@
String queryString = request.getParameter("query");
if (queryString == null)
throw new ServletException("no query specified");
+ String maxHostHitsString = request.getParameter("maxHostHits");
+ if(maxHostHitsString == null)
+ maxHostHitsString = "1";
+ int maxHostHits = Integer.parseInt(maxHostHitsString);
String htmlQueryString = net.nutch.html.Entities.encode(request.getParameter("query"));
int start = 0; // first hit to display
@@ -32,7 +36,6 @@
String hitsString = request.getParameter("hitsPerPage");
if (hitsString != null)
hitsPerPage = Integer.parseInt(hitsString);
-
Query query = Query.parse(queryString);
bean.LOG.info("query: " + queryString);
@@ -72,52 +75,63 @@
<input type="submit" value="<i18n:message key="search"/>">
</form>
<%
- // perform query
- Hits hits = bean.search(query, start + hitsPerPage);
- int end = (int)Math.min(hits.getTotal(), start + hitsPerPage);
- int length = end-start;
- Hit[] show = hits.getHits(start, length);
- HitDetails[] details = bean.getDetails(show);
- String[] summaries = bean.getSummary(details, query);
- bean.LOG.info("total hits: " + hits.getTotal());
+HostHits hosthits = bean.searchGroupedByPage(query,100000,hitsPerPage);
+int end = (int)Math.min(hosthits.getTotal(), start + hitsPerPage);
+int length = end-start;
+
+bean.LOG.info("total hits: " + hosthits.getTotal());
%>
<i18n:message key="hits">
<i18n:messageArg value="<%=new Long(start+1)%>"/>
<i18n:messageArg value="<%=new Long(end)%>"/>
- <i18n:messageArg value="<%=new Long(hits.getTotal())%>"/>
+ <i18n:messageArg value="<%=new Long(hosthits.getTotal())%>"/>
</i18n:message>
-
-<%
- for (int i = 0; i < length; i++) { // display the hits
- Hit hit = show[i];
- HitDetails detail = details[i];
- String title = detail.getValue("title");
- String url = detail.getValue("url");
- String summary = summaries[i];
- String id = "idx=" + hit.getIndexNo() + "&id=" + hit.getIndexDocNo();
-
- if (title == null || title.equals("")) // use url for docs w/o title
- title = url;
- %>
- <br><br><b>
- <a href="<%=url%>"><%=Entities.encode(title)%></a>
- </b>
- <% if (!"".equals(summary)) { %>
- <br><%=summary%>
- <% } %>
- <br>
- <span class="url"><%=Entities.encode(url)%></span>
- (<a href="/cached.jsp?<%=id%>"><i18n:message key="cached"/></a>)
- (<a href="/explain.jsp?<%=id%>&query=<%=URLEncoder.encode(queryString)%>"><i18n:message key="explain"/></a>)
- (<a href="/anchors.jsp?<%=id%>"><i18n:message key="anchors"/></a>)
-<% } %>
-
+<br>
<%
- bean.LOG.info("done displaying hits");
-
- if (end < hits.getTotal()) { // insert next page button
+for(int i=0;i<length;i++)
+{
+ Hit[] hits = hosthits.getHostHit(i+start).getHits();
+ HitDetails[] details = bean.getDetails(hits);
+ //String[] summaries = bean.getSummary(details,query);
+
+ for(int h=0;h<hits.length;h++)
+ {
+ Hit hit = hits[h];
+ HitDetails detail = details[h];
+ String title = detail.getValue("title");
+ String url = detail.getValue("url");
+ String summary = bean.getSummary(detail,query);
+ String id = "idx=" + hit.getIndexNo() + "&id=" + hit.getIndexDocNo();
+ if (title == null || title.equals("")) // use url for docs w/o title
+ title = url;
+ if(!(h>=maxHostHits+1))
+ {
+ if(h>0){%><blockquote><%}
+ else{%><br><%}
+ %>
+
+ <b>
+ <a href="<%=url%>"><%=Entities.encode(title)%></a>
+ </b>
+ <% if (!"".equals(summary)) { %>
+ <br><%=summary%>
+ <% } %>
+ <br>
+ <span class="url"><%=Entities.encode(url)%></span>
+ (<a href="/cached.jsp?<%=id%>"><i18n:message key="cached"/></a>)
+ (<a href="/explain.jsp?<%=id%>&query=<%=URLEncoder.encode(queryString)%>"><i18n:message key="explain"/></a>)
+ (<a href="/anchors.jsp?<%=id%>"><i18n:message key="anchors"/></a>)
+ <%
+ if(h>0){%></blockquote><%}
+ else{%><br><%}
+ }
+ }
+
+}
+bean.LOG.info("done displaying hits");
+ if (end < hosthits.getTotal()) { // insert next page button
%>
<form name="search" action="/search.jsp" method="get">
<input type="hidden" name="query" value="<%=htmlQueryString%>">
@@ -128,11 +142,11 @@
<%
}
%>
-
+<div align=right>
<a href="http://www.nutch.org/">
<img border="0" src="/img/poweredbynutch_01.gif">
</a>
-
+</div>
<jsp:include page="/include/footer.html"/>
</body>