Skip to main content

Adobe

Finding Content Without a Tag With AEM Query Builder

Olav Ahrens Rotne 4ennrbj1svk Unsplash

Recently, I came across a requirement where we needed to build a complex query. The query was all the combinations of the title predicate, date predicate, and tags predicates to search for the page results.

One of the parts in the given requirement was to search the pages that did not include a specific tag. Let’s check out a simple example.

In this example, there are three demo pages (demo-page-1, demo-page-2 and demo-page-3), each containing some specific tags.

Aem crxde page hierarchy

I have applied two tags on demo-page-1. In the same way, I have applied the tags for other two pages also.

Aem page properties Page1 Tags

Now, I want to search the pages which don’t include the tag tagsearch:model/sampleModel1. So, by using the property operation unequals, I found the query works perfectly fine if only one tag is assigned to the page. For instance, only tagsearch:model/sampleModel1 present in the cq:tags page property.

Aem Query Builder Unequals

In the above screenshot, I was getting the perfect result. The demo-page-1 was excluded from the result, which was expected. But, when there were multiple tags assigned, the cq:tags property of the page as shown in previous image. The results were not as expected. The results included the demo-page-1 and I was expecting the result to exclude that page as the tag present there.

How-To Resolve

To resolve this issue, I applied one workaround. I created the query like this:

path=/content/project-name/en/us/predicate-demo
type=cq:Page
1_group.p.not=true
1_group.1_property=jcr:content/cq:tags
1_group.1_property.value=tagsearch:model/sampleModel1
1_group.1_property.operation=equals

It worked for me and I got the expected results of what I was looking for.

Aem Query Negation

We can use the above query example according to our requirement to create the query map. Therefore, we can write the conditions. For instance, if the property contains cq:tags and the operation is unequal, then we can create the query like the below:

path=/content/project-name/en/us/predicate-demo
type=cq:Page
1_group.100_group.p.not=true
1_group.100_group.1_property=jcr:content/cq:tags
1_group.100_group.1_property.value=tagsearch:model/sampleModel1
1_group.100_group.1_property.operation=equals

The 100_group is just a random text to make the (1_group.100_group) group unique, so that the 1_group.100_group.p.not=true will not be effected by the other group that is using it in the query builder.

path=/content/project-name/en/us/predicate-demo
type=cq:Page
1_group.p.or=true
1_group.100_group.p.not=true
1_group.0_daterange.property=jcr:content/onTime
1_group.0_daterange.upperBound=2020-03-27T14:18:00.000+05:30
1_group.1_property=jcr:content/pageTitle
1_group.1_property.value=searchValue
1_group.100_group.1_property=jcr:content/cq:tags
1_group.100_group.1_property.value=tagsearch:model/sampleModel1
1_group.100_group.1_property.operation=equals

In the above example, 1_group.100_group.p.not=true won’t negate 1_group.1_property=jcr:content/pageTitle results.

I hope you for this blog useful. Don’t forget to drop a comment in the section below if you need more help with this solution. Be sure to check out our entire Adobe blog collection for more helpful tips and tricks.

Thoughts on “Finding Content Without a Tag With AEM Query Builder”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Rahul Kopulwar, Technical Consultant

Rahul is Adobe Experience Manager Developer.

More from this Author

Categories
Follow Us