On a recent implementation, a large site fully driven by OData, we ran into a scenario where we wanted to retrieve DCPs based on multiple custom metadata values. We quickly realized that there are some limitations around this. For instance: a component with the following custom meta fields, color and shape, having values ‘blue’ and ‘round’ respectively cannot be retrieved in one OData call. This is because each CustomMetas Key/Value is exposed as a separate entry in the CustomMetas collection, and the OData protocol is limited – doesn’t allow querying across properties of multiple entries (not as an AND at least). However, if there is a will there is a way, and in the article I will show an approach to doing so.
Contents:
- Part 1 – Examining the Problem
- Part 2 – The Generic Workaround
- Part 3 – The Multi-Meta Query Solution
Nice approach, Nick! I personally would have just executed multiple queries and then intersected the results in app-logic. But that would be lots more bytes over the wire.
As you know, I recently experimented with OData Query Extension (http://yatb.mitza.net/2013/06/url-syntax-for-odata-query-extension.html) and your query could be re-written as:
/odata.svc/QueryComponentPresentations(SchemaTitle=Article)?$filter=ComponentMetaValue(ComponentMetaKey(‘color’), ‘red’) and ComponentMetaValue(ComponentMetaKey(‘shape’), ’round’)
… which would be parsed into a Criteria object and performed by CD API on the OData server.
Thanks for the comment Mihai. I really like your approach. I do hope that future releases of the CD Web Service will have this capability built-in.
As a side note, I recall having a conversation with someone from R&D, and he mentioned that OData on the back side does not wrap the standard CD API as I had assumed. It uses a totally redesigned set of DB queries which are much more performant than those of the classic CD API.
Hi Nickoli,
Is this issue solved in Web 8 or 8.5 with Content Service microservice?
That’s a great question. The new version of Tridion supports GraphQL, which is supposed to be a lot more flexible for querying. I’ve not done a POC on this specifically yet. Please share your findings with us if you get there first.
There are some examples of ‘or’ joins around the 47 minute mark in the following SDL BrightTALK about Tridion Sites 9 and the new Public Content API:
https://www.brighttalk.com/webcast/15345/327155?utm_source=SDL&utm_medium=brighttalk&utm_campaign=327155