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.

I have applied two tags on demo-page-1. In the same way, I have applied the tags for other two pages also.
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.

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.

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:
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
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.

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
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.
No comments:
Post a Comment
If you have any doubts or questions, please let us know.