Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AEM Predicate - how to check if property starts with / contains string?

I'm using query builder to search for images in DAM. I use predicates to do that. I'm trying to check metadata dam:MIMEtype property, to return all nodes which starts from image/.

How can I do that?

like image 230
Ma Kro Avatar asked Dec 24 '22 22:12

Ma Kro


1 Answers

You can use the JcrPropertyPredicateEvaluator to achieve the same.

Assuming that you are searching the path /content/dam for all dam:Asset's whose dam:MIMEtype starts with image/ the query would be

path=/content/dam
type=dam:Asset
property=jcr:content/metadata/dam:MIMEtype
property.value=image/%
property.operation=like
p.limit=-1

The corresponding XPATH query would be

/jcr:root/content/dam//element(*, dam:Asset)
[
jcr:like(jcr:content/metadata/@dam:MIMEtype, 'image/%') 
]

You can try executing the above query in your instance's query debugger(/libs/cq/search/content/querydebug.html) and verify if the results are fine.

PredicateEvaluator Docs and the QueryBuilder API might provide more insights on writing queries.

like image 141
rakhi4110 Avatar answered Jan 05 '23 17:01

rakhi4110