[MRM-861]

-added pagination to search results page


git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@675415 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Maria Odea B. Ching 2008-07-10 02:17:04 +00:00
parent 15b6ddae0b
commit 2b2e21c613
6 changed files with 96 additions and 6 deletions

View File

@ -45,7 +45,7 @@ import org.codehaus.plexus.xwork.action.PlexusActionSupport;
*/
public class SearchAction
extends PlexusActionSupport
{
{
/**
* Query string.
*/
@ -76,6 +76,10 @@ public class SearchAction
private static final String ARTIFACT = "artifact";
private List databaseResults;
private int currentPage = 0;
private int totalPages;
public String quickSearch()
throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException
@ -87,8 +91,8 @@ public class SearchAction
*/
assert q != null && q.length() != 0;
SearchResultLimits limits = new SearchResultLimits( 0 );
SearchResultLimits limits = new SearchResultLimits( currentPage );
List<String> selectedRepos = getObservableRepos();
if ( CollectionUtils.isEmpty( selectedRepos ) )
@ -103,7 +107,9 @@ public class SearchAction
addActionError( "No results found" );
return INPUT;
}
totalPages = results.getTotalHits() / limits.getPageSize();
// TODO: filter / combine the artifacts by version? (is that even possible with non-artifact hits?)
/* I don't think that we should, as I expect us to utilize the 'score' system in lucene in
@ -197,4 +203,24 @@ public class SearchAction
{
return databaseResults;
}
public void setCurrentPage( int page )
{
this.currentPage = page;
}
public int getCurrentPage()
{
return currentPage;
}
public int getTotalPages()
{
return totalPages;
}
public void setTotalPages( int totalPages )
{
this.totalPages = totalPages;
}
}

View File

@ -32,6 +32,11 @@
<h1>Search</h1>
<c:url var="imgNextPageUrl" value="/images/icon_next_page.gif"/>
<c:url var="imgPrevPageUrl" value="/images/icon_prev_page.gif"/>
<c:url var="imgPrevPageDisabledUrl" value="/images/icon_prev_page_disabled.gif"/>
<c:url var="imgNextPageDisabledUrl" value="/images/icon_next_page_disabled.gif"/>
<div id="contentArea">
<div id="searchBox">
<%@ include file="/WEB-INF/jsp/include/quickSearchForm.jspf" %>
@ -44,13 +49,72 @@
<%-- search was made from the indices --%>
<c:when test="${databaseResults == null}">
<p>Hits: ${fn:length(results.hits)} of ${results.totalHits}</p>
<c:set var="hitsNum">${fn:length(results.hits) + (currentPage * 31)}</c:set>
<p>Hits: ${hitsNum - 30} to ${hitsNum} of ${results.totalHits}</p>
<c:choose>
<c:when test="${empty results.hits}">
<p>No results</p>
</c:when>
<c:otherwise>
<%-- Pagination start --%>
<p>
<%-- Prev & Next icons --%>
<c:set var="prevPageUrl">
<ww:url action="quickSearch" namespace="/">
<ww:param name="q" value="%{'${q}'}"/>
<ww:param name="currentPage" value="%{'${currentPage - 1}'}"/>
</ww:url>
</c:set>
<c:set var="nextPageUrl">
<ww:url action="quickSearch" namespace="/">
<ww:param name="q" value="%{'${q}'}"/>
<ww:param name="currentPage" value="%{'${currentPage + 1}'}"/>
</ww:url>
</c:set>
<c:choose>
<c:when test="${currentPage == 0}">
<img src="${imgPrevPageDisabledUrl}"/>
</c:when>
<c:otherwise>
<a href="${prevPageUrl}">
<img src="${imgPrevPageUrl}"/>
</a>
</c:otherwise>
</c:choose>
<c:forEach var="i" begin="0" end="${totalPages - 1}">
<c:choose>
<c:when test="${ (i != currentPage) }">
<c:set var="specificPageUrl">
<ww:url action="quickSearch" namespace="/">
<ww:param name="q" value="%{'${q}'}"/>
<ww:param name="currentPage" value="%{'${i}'}"/>
</ww:url>
</c:set>
<a href="${specificPageUrl}">${i + 1}</a>
</c:when>
<c:otherwise>
<b>${i + 1}</b>
</c:otherwise>
</c:choose>
</c:forEach>
<c:choose>
<c:when test="${ currentPage eq ( totalPages - 1 ) }">
<img src="${imgNextPageDisabledUrl}"/>
</c:when>
<c:otherwise>
<a href="${nextPageUrl}">
<img src="${imgNextPageUrl}"/>
</a>
</c:otherwise>
</c:choose>
</p>
<%-- Pagination end --%>
<c:forEach items="${results.hits}" var="record" varStatus="i">
<c:choose>
<c:when test="${not empty (record.groupId)}">

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 B