[solved] How to search articles on space by title (same as sql like.) via the XWQL?

Hi,

How to search articles on space by XWQL ? 

For example:

In the Sandbox space, here are 3 articles: 

http://...com/bin/view/Sandbox/TestPage1
http://...com/bin/view/Sandbox/TestPage2
http://...com/bin/view/Sandbox/Test3

so, how to search the articles title begin with TestPage? and the result is: (not contains Test3)
http://...com/bin/view/Sandbox/TestPage1
http://...com/bin/view/Sandbox/TestPage2

Thanks
Bayern

Hi,

there is a quite extensive documentation for xwql available here.
Also you can use the like operator as you would in normal SQL, e.g. where doc.Name like 'TestPage%' and doc.Space='Sandbox'

To be honest, I was not able to test the query, so it could need a little tweaking.

Hope that helps.

rbr

Hello,

For this point a nice extension: http://extensions.xwiki.org/xwiki/bin/view/Extension/Query+Tester

Pascal B

1 Like

Thank you very much, it’s a nice tool. @Pbas

This code it works.

{{velocity}}
#set($xwql = “from XWikiSpace as space where doc.space = ‘Sandbox’ and doc.name like ‘TestPage%’”)
#set($results = $services.query.xwql($xwql).addFilter(“unique”).execute())
#if($results.empty)
#else
#foreach ($item in $results)
#set($faq = $xwiki.getDocument($item))
* [[${faq.display(“question”).replace("

", “”).replace("

", “”)}>>${item}]]
#end

{{/velocity}}

Hi @Pbas,

thanks for the hint. I already use the extension. The problem was more of “I don’t have access to my server” (because I was in the on the way) than “I have no clue how to test this”. :wink:

Still it helped @anim510 and that is even better.

@anim510: Are you sure you need the

part? You are not referencing “space” anywhere in your query and although it looks strange at the beginning where a=b is a complete xwql query. See this chapter for an explanation of the expansion of the short form.

rbr

@rbr

You’re right , the XWQL statement is fine, don’t need the from part.

1 Like

Thanks!