How to List all pages starting with a specific alphabet?

Hi,

I am new to XWiki and have added some pages in it. What I want is to create a new page that can list the titles + link to all the pages in XWiki that start with particular alphabet. For example, I would like to get a list of all the pages that start with letter β€œE”. Any help in query is highly appreciated.

Hi, that’s easy to do, check the query module doc at https://extensions.xwiki.org/xwiki/bin/view/Extension/Query%20Module

For example:

{{velocity}}
#set ($xwql = "where doc.name like 'E%'")
#foreach ($item in $services.query.xwql($xwql).execute())
  * [[$item]]
#end
{{/velocity}}
1 Like

@vmassol,

Thanks for sharing the code. But it lists those pages which are like by default of XWiki. I want it to return only those pages which are created by users. Can you please help?

Also, what if I want to specify the search letter through some external link from another website? e.g. if I have a webpage where a search box is there and I want to give user ability to search for all pages from XWiki that start with β€œE”.

Highly appreciate your help in this regard.

Hello,
Like @vmassol said about this doc:

#set ($xwql = "where doc.name like 'E%' and doc.author = 'XWiki.LudovicDubost'")

(bindValue from same doc) you can give some parameter in the URL:

#set ($query = $services.query.xwql(""where doc.name like :MyLetter"))
#set ($MyLetter = "$!{request.get('firstletter')}")
#set ($query = $query.bindValue('MyLetter', "${MyLetter}%"))
$query.execute()

You can use this URL: bin/view/MySpace/MyPage?firstletter=E

Pascal