Expand my Community achievements bar.

SOLVED

Issue With Making QueryBuilder Predicate for Tags

Avatar

Level 2

Hi Folks,

I had a question about building an QueryBuilder predicates in AEM java. 

I'm building a predicate that tests for more than one tag. The tag types are different, belonging to different groups in the Tag library. Here's a snippet of my code:

map.put("type", "cq:Page"); map.put("1_property", "jcr:content/cq:tags"); map.put("1_property.value",tag1); map.put("2_property","jcr:content/cq:tags"); map.put("2_property.value",tag2); map.put("3_property","jcr:content/cq:tags"); map.put("3_property.value",tag3); map.put("p.offset", "0"); map.put("p.limit", "100");

When I do this, and I tag a page, this is the behavior I'm noticing:

1. If I add tags to my page(s), and make a request for pages that contain the exact tags that I added, I get my page(s) back in the response.

2. If I add tags to my page(s), and I request for pages that have the same type/classification of tags (but not the exact same tags), I do not get a result back. This is correct behavior, and desired.

3. If I add some, but not all tags to the page, and then I make the same request for all of the tags, I still get a result back. I do not want this to happen. The request matched on some tags, but other tags were missing altogether from the page - but the page was still returned.

In other words, if a request for a tag is mismatched to the tag on a page, that page is ignored. But if a request for a tag is made and that group/class of tag is not on the page at all, the page is still returned if the query matched on the other tags. I don't want that to happen.

How can I remodel my predicate to return a page only if it has the exact tags requested, and not return a page if the requested tags are not the same OR if the requested tags are missing on the page?

If you need any clarification, please let me know, I'll be happy to oblige. Thank you.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Try this, it should work

type=cq:Page
path=/content/project
1_tagid=geometrixx-media:entertainment/music
1_tagid.property=jcr:content/cq:tags
2_tagid=geometrixx-media:entertainment/movies
2_tagid.property=jcr:content/cq:tags

View solution in original post

5 Replies

Avatar

Level 10

"I had a question about building an QueryBuilder predicates in AEM java"

Take a look at this artilce - it was based on a similar use case and a custom PredicateGroup was used: 

https://helpx.adobe.com/experience-manager/using/customtags1.html

Avatar

Administrator

Adding resources on top of what Scott has already shared:-

Link:- http://labs.6dglobal.com/blog/2014-06-28/creating-a-custom-predicate-for-querying-by-version

// Creating a Custom Predicate for Querying by Version

Link:- https://aemquickstart.blogspot.in/2015/12/create-custom-query-predicate-in-aem.html

// Create custom query predicate in AEM

I hope this would help you.

~kautuk



Kautuk Sahni

Avatar

Level 10

As per my understanding, when you query tag1 and tag2

you want the list of pages which has both the tags (tag1 + tag2)

Let me know if I understood properly or not?

Avatar

Correct answer by
Level 10

Try this, it should work

type=cq:Page
path=/content/project
1_tagid=geometrixx-media:entertainment/music
1_tagid.property=jcr:content/cq:tags
2_tagid=geometrixx-media:entertainment/movies
2_tagid.property=jcr:content/cq:tags

Avatar

Administrator

Please test the solution that Praveen suggested here.

~kautuk



Kautuk Sahni