Tuesday, 11 February 2014

Adobe CQ/AEM Query Builder - empty property

So at work, I was faced with a scenario where I have to use the CQ query builder to retrieve a bunch of articles that when they do not have a date property it will be selected along with the ones with date property that does not expire.

A little pseudo-code to show what I mean:

if (!article.hasDate) {
  return true;
} else {
  if (article.date >= now()) {
    return true;
  }
  return false;
}

Here are some articles I found online before I came up with a solution:



Finally, here is what I have in CQ query builder:

path=[path/to/articles]
type=cq:Page
99_property=@jcr:content/cq:template
99_property.value=[apps/path/to/template]
10_group.p.or=true
10_group.1_property=@jcr:content/offTime
10_group.1_property.operation=not
10_group.2_daterange.property=@jcr:content/offTime
10_group.2_daterange.lowerBound=[current-date-or-hardcode-date-for-testing]
10_group.2_daterange.lowerOperation=>=

This is now returning articles that does NOT have the offTime property; also it returns articles that DO have the offTime date and are current.

1 comment: