原文来自http://blog.chinaunix.net/u1/50183/showart_395349.html
搜索引擎nutch在查询搜索结果时,只有下一页功能。现在实现了分页功能,并把是show all hits删去
1.删去show all hits
修改:
int hitsPerSite = 0; // max hits per site
2.分页功能
<table align="center">
<tr>
<td>
<%
if (start >= hitsPerPage) // more hits to show
{
%>
<form name="pre" action="../search.jsp" method="get">
<input type="hidden" name="query" value="<%=htmlQueryString%>">
<input type="hidden" name="lang" value="<%=queryLang%>">
<input type="hidden" name="start" value="<%=start - hitsPerPage%>">
<input type="hidden" name="hitsPerPage" value="<%=hitsPerPage%>">
<input type="hidden" name="hitsPerSite" value="<%=hitsPerSite%>">
<input type="hidden" name="clustering" value="<%=clustering%>">
<input type="submit" value="上一页">
<%} %>
</form>
<%
int startnum=1;//页面中最前面的页码编号,我设定(满足)共10页,当页为第6页
if((int)(start/hitsPerPage)>=5)
startnum=(int)(start/hitsPerPage)-4;
for(int i=hitsPerPage*(startnum-1),j=0;i<=hits.getTotal()&&j<=10;)
{
%>
<td>
<form name="next" action="../search.jsp" method="get">
<input type="hidden" name="query" value="<%=htmlQueryString%>">
<input type="hidden" name="lang" value="<%=queryLang%>">
<input type="hidden" name="start" value="<%=i%>">
<input type="hidden" name="hitsPerPage" value="<%=hitsPerPage%>">
<input type="hidden" name="hitsPerSite" value="<%=hitsPerSite%>">
<input type="hidden" name="clustering" value="<%=clustering%>">
<input type="submit" value="<%=i/hitsPerPage+1 %>">
</form>
</td>
<%
i=i+5;
j++;
}
%>
<td>
<%
if ((hits.totalIsExact() && end < hits.getTotal()) // more hits to show
|| (!hits.totalIsExact() && (hits.getLength() > start
+ hitsPerPage))) {
%>
<form name="next" action="../search.jsp" method="get">
<input type="hidden" name="query" value="<%=htmlQueryString%>">
<input type="hidden" name="lang" value="<%=queryLang%>">
<input type="hidden" name="start" value="<%=end%>">
<input type="hidden" name="hitsPerPage" value="<%=hitsPerPage%>">
<input type="hidden" name="hitsPerSite" value="<%=hitsPerSite%>">
<input type="hidden" name="clustering" value="<%=clustering%>">
<input type="submit" value="<i18n:message key="next"/>">//下一页
</form>
<%} %>
</td>
</tr>
</table>