Comments on Query Module

Last modified by Gabriel R─âileanu on 2020/09/11 17:05

  • Danilo Oliveira
    Danilo Oliveira, 2014/07/17 23:48

    If you need retrieve random results from some search you can try to use the random parameter in the SQL statement. For example, in the example below we retrieve 2 docs of a specific class randomly:

    #set($hql0 = ", BaseObject as obj where doc.fullName = and doc.fullName != 'Filmes.FilmesTemplate' and (obj.className = 'Filmes.FilmesClass') order by rand() desc")
    #set ($listProjetos = $services.query.hql($hql0).setLimit(2).execute())
  • Thomas Menamparampan
    Thomas Menamparampan, 2018/06/01 03:35

    if you need to search for not tagged pages in your wiki and have a page listed with hyperlink please do this:

    ##The query pulls out every pages that has any tag and then put into a list
    #set ($list2 = $services.query.xwql("from doc.object(XWiki.TagClass) as tag").execute() )
    ##The query pulls out every pages that was created since September 2017 and then put into a list
    #set ($list1 = $services.query.xwql("where doc.creationDate > :date").bindValue('date', $datetool.toDate('yyyy-MM-dd', '2017-09-01')).execute() )

    ##create a new list using for loop to get all items that are in list 1 but not in list 2 and call it as list3
    #set ($list3 = [])
    #foreach($ref1 in $list1)
      #set ($found = false)
      #foreach($ref2 in $list2)
        #if ($ref1 == $ref2)
          #set ($found = true)
      #if ($found == false)
        #set ($temp = $list3.add($ref1))  
    ##creation of list of pages with hyperlink for the new list3 (pages with no tags)
     #foreach($reference in $list3)
    #set ($document = $xwiki.getDocument($reference))
    #set ($label = $document.getTitle())
  • Camille Desmots
    Camille Desmots, 2019/02/08 11:20

    A Groovy script that will list all the wikis:

    import com.xpn.xwiki.api.XWiki;
    List<String> listeDesWikis;
    listeDesWikis = xwiki.getWikiNames();
    println "List of the wikis:"
    for (currentWikiName in listeDesWikis) {
       println "* ${currentWikiName}";

Get Connected