Query for articles with specific tag (in specific space)

Hi.

I want to list all pages with specific tag with a xwql query as I want to have later the possibility to enlarge the query to reduce it to a specific space.

This is what I have so far but it’s not working. Without the “if” it will list all articles with any tag.

#set($allDocWithTag = $services.query.xwql('from doc.object("XWiki.TagClass") as tags order by doc.space').addFilter('unique').execute())
#foreach($doc in $allDocWithTag)
  #if($doc.getObject('XWiki.TagClass', 'Tags', 'test'))
    $doc
  #end
#end

I’m aware of [Solved] Display a list of pages with a specific tag - #10 by Mayot

#set ($list = $xwiki.tag.getDocumentsWithTag('test'))
#foreach($reference in $list)
  #set ($document = $xwiki.getDocument($reference))
  #set ($label = $document.getTitle())
  [[$label>>$reference]]
#end 

But as i said I later want to search only for articles with that specific tag inside a specific space. And I don’t see a good possibility for that with the second approach.

Any hints for me?
Regards, Simpel

Hi,

Please take a look at examples in Query Module (XWiki.org). There is one related to tags that indicates that you’re missing the tag name check in your query: from doc.object(XWiki.TagClass) as tag where 'test' member of tag.tags. You can also bind the space to filter your results. See also the bindValue() examples in the same documentation page.

Hope it helps,
Alex

@acotiuga I am very confused as I tried your suggestion first. But that did not work. (Error message like “expect SELECT” or so.) Maybe I mixed hql and xwql that time?

This is now working:

{{velocity}}
#set($allDocWithTag = $services.query.xwql("from doc.object(XWiki.TagClass) as tag where 'test' member of tag.tags order by doc.space").addFilter('unique').execute())
#foreach($doc in $allDocWithTag)
  * $doc
#end
{{/velocity}}