0

We are implementing a custom REST endpoint in magnolia that queries for pages and it should be able to filter by categories. I found the JCR Query Cheat Sheet, but I could not see an example about filtering a multivalued field. In our case, we have a categories field with an array of category UUIDs and I want all pages having a certain category uuid. It works with using a like query (lets say 123-456 is a uuid) such as:

"SELECT * FROM [mgnl:page] p where p.[categories] like '%123-456%'

Is there a better approach without using (possible slow) LIKE queries to explicitly check for an intersection with the categories array? Are there any SET/ARRAY functions to use in where conditions for such filtering?

Andre Albert
  • 1,386
  • 8
  • 17

1 Answers1

1

In case of multifield values, you can put multiple WHERE statements like so:

SELECT * FROM [mgnl:content] AS p 
   WHERE p.[categories] = '415025c6-e4b5-4506-9384-34f428a52104'
   AND p.[categories] = 'e007e401-1bf8-4658-8293-b9c743784264'

This will return nodes in which categories (multivalue) property contains both IDs.

RobSis
  • 342
  • 2
  • 10