You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nutch.apache.org by "Jack Tang (JIRA)" <ji...@apache.org> on 2005/04/07 11:57:18 UTC

[jira] Commented: (NUTCH-39) pagination in search result

     [ http://issues.apache.org/jira/browse/NUTCH-39?page=comments#action_62343 ]
     
Jack Tang commented on NUTCH-39:
--------------------------------

And here is my solution. I only add the pagination in Intranet search. You can follow below steps:

1. Add some attribues into search.jsp to support pagination.

  /**
   * -----------------------------------------------------------------------
   * Page navigation attributes
   * 
   *                 supposedRange
   *               |<------------->|
   *   Previous << 1    2    3    4  >> Next
   *               ^
   *               pivot  
   *   
   *                        forward 
   *                         |<-->|
   *   Previous << 3    4    5    6  >> Next
   *               ^
   */
  private static int supposedRange = 4; // items show in naviagtion
  private static int pivot = 1;         // pivot in the page navigation
  private static long[] history = new long[]{0,0}; // use click footprint
  int forward = 1;                      // the distance navigation window will move forward
  
  //-------------------------------------------------------------------------

2. Replace "Next" button with pagination
a) the code to be removed 
<%

if ((hits.totalIsExact() && end < hits.getTotal()) // more hits to show
    || (!hits.totalIsExact() && (hits.getLength() > start+hitsPerPage))) {
%>
    <form name="search" action="../search.jsp" method="get">
    <input type="hidden" name="query" value="<%=htmlQueryString%>">
    <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>
<%
    }
%>
b) the codes to be added
<%

if ((hits.totalIsExact() //&& end < hits.getTotal()) // more hits to show
    //|| (!hits.totalIsExact() && (hits.getLength() > start+hitsPerPage))) 
   )){
%>
    	<%  
    		long curP = end/hitsPerPage + (end%hitsPerPage > 0 ? 1:0); // get current page
    		end = end % hitsPerPage > 0? (end/hitsPerPage + 1)*hitsPerPage : end; // fix end page
    		
    	    long actualRange = hits.getTotal() / hitsPerPage + (hits.getTotal()%hitsPerPage > 0 ? 1: 0); // total pages after searching 
			long range = Math.min(supposedRange,actualRange); // used below
			
			/**
			 *  +---+ 
			 *  | 1 | <-- current click
			 *  |---|
			 *  | 0 | <-- previouse click
			 *  +---+
			 */
			history[0] = history[1]; 
			history[1] = curP;
			
			if(curP > range)
			{
			   if(curP - pivot >= range) // Now, current page in at the edge of navigation window
				   if(history[0] < history[1]) // and use click "Next" again
						pivot += forward; 
				   else
						pivot -= forward;      // otherwise, he click the "Previouse" button
			} else
			{
				pivot = 1;
			}
    	%>
	
    <div id=result>
    <p>

		<b>Results Page:</b><br>
	
	<% // Previouse button(<<)	%>
	<%if(curP > 1){%>
		<big><b><a href="../search.jsp?query=<%=URLEncoder.encode(queryString,"UTF-8")%>&start=<%=end - 2*hitsPerPage %>&hitsPerPage=<%=hitsPerPage%>&hitsPerSite=<%=hitsPerSite%>&clustering=<%=clustering%>&pivot=<%=pivot%>">Prev</a></b></big>&nbsp;
		<a href="../search.jsp?query=<%=URLEncoder.encode(queryString,"UTF-8")%>&start=<%=end- 2*hitsPerPage %>&hitsPerPage=<%=hitsPerPage%>&hitsPerSite=<%=hitsPerSite%>&=<%=clustering%>&pivot=<%=pivot%>"><img src=../img/ar_prev.gif width=7 height=13 border=0 alt=""></a>&nbsp;
	<%}%>
	<% // Navigation window    %>
		<%
			long prevStart = 0;
			long nextStart = 0;
			for(int i=pivot; i< range + pivot; i++)
			{
				prevStart = end - (curP - i + 1) * hitsPerPage; // previouse
				nextStart = end + (i - curP - 1) * hitsPerPage;  // next
				
				if( i < curP )
					out.println("<a href=\"../search.jsp?query=" + URLEncoder.encode(queryString,"UTF-8") + "&start=" + prevStart + "&hitsPerPage=" + hitsPerPage + "&hitsPerSite=" + hitsPerSite + "&clustering=" + clustering + "&pivot="  + pivot + "\" title=\"Results " + (prevStart + 1) + " - " + (prevStart + hitsPerPage) + "\"> "+ i + "</a>&nbsp;");
				else 
				if( i == curP)
					out.println(i + "&nbsp;");
				else
					out.println("<a href=\"../search.jsp?query=" + URLEncoder.encode(queryString,"UTF-8") + "&start=" + nextStart + "&hitsPerPage=" + hitsPerPage + "&hitsPerSite=" + hitsPerSite + "&clustering=" + clustering + "&pivot="  + pivot + "\" title=\"Results " + (nextStart + hitsPerPage + 1) + " - " + (Math.min(nextStart + 2 * hitsPerPage,hits.getTotal())) + "\"> "+ i + "</a>&nbsp;");
			}
			
		%>
	<% // Next button (>>)%>	
	<%if((end < hits.getTotal())){%>	
		<a href="../search.jsp?query=<%=URLEncoder.encode(queryString,"UTF-8")%>&start=<%=end%>&hitsPerPage=<%=hitsPerPage%>&hitsPerSite=<%=hitsPerSite%>&=<%=clustering%>"><img src=../img/ar_next.gif width=7 height=13 border=0 alt=""></a>&nbsp;
		<big><b><a href="../search.jsp?query=<%=URLEncoder.encode(queryString,"UTF-8")%>&start=<%=end%>&hitsPerPage=<%=hitsPerPage%>&hitsPerSite=<%=hitsPerSite%>&clustering=<%=clustering%>&pivot=<%=pivot%>">Next</a></b></big>
	<%}%>
	</p>
	</div>
<%
    } 
%>




> pagination in search result
> ---------------------------
>
>          Key: NUTCH-39
>          URL: http://issues.apache.org/jira/browse/NUTCH-39
>      Project: Nutch
>         Type: Improvement
>   Components: web gui
>  Environment: all
>     Reporter: Jack Tang
>     Priority: Trivial

>
> Now in nutch search.jsp, user navigate all search result using "Next" button. And google like pagination will feel better.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira