cogDisplay results from a hql query in multiple pages
TypeSnippet
Category
Developed by

Jean-Vincent Drean

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Table of contents

Description

Early release. Work in progress

Code

#macro(paginateSearch $query $currentPage $resultsPerPage)
#set ($start = $resultsPerPage * $currentPage)
#set ($resultsnb = $xwiki.xWiki.search("select count(doc) from
XWikiDocument doc ${query}", $context.context).get(0))
#set ($list = $xwiki.searchDocuments($query, $resultsPerPage, $start))
#foreach ($item in $list)
 * $item
#end
#if ($resultsnb > $resultsPerPage)
 #set ($pagesnb = $resultsnb / $resultsPerPage)
 #foreach ($pagenb in [0..$pagesnb])
   #if ($pagenb != $currentPage)
     [$pagenb>$doc.fullName?page=$pagenb]
   #else
     $pagenb
   #end
 #end
#end
#end

#if ($request.page)
 #set ($page = $xwiki.parseInt($request.page))
#else
 #set ($page = 0)
#end

#paginateSearch("where 1=1" $page 5)

Result

  • Main.Tags
  • Main.TagsRss
  • Main.WebHome
  • Main.WebRss
  • Main.WebSearch
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Tags: presentation
     

Get Connected