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

1

5

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?

Starobin answered 23/2, 2015 at 22:17 Comment(0)
A
12

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.

Abbevillian answered 24/2, 2015 at 4:37 Comment(1)
for ends-with or contains, we can try %image and %image% respectively. w3schools.com/sql/sql_like.aspFindley

© 2022 - 2024 — McMap. All rights reserved.