I have a schema with a multi-value custom meta field. So when a component is published I'd like to retrieve it by the selected values in this meta field. I need to pull back the exact matches.
- I have Component A with field values val1, val2 and val3.
- I also have Component B with values val1.
- And I a Component C with values val3.
I am trying to construct a query to retrieve only Component A, i.e. val1 AND val2 AND val3.
We can't AND (
CustomMetaValueCriterias, as this will never yield true due to Custom Metas being separate records in the DB. It seems to be the same story as documented here: http://www.tridiondeveloper.com/odata-how-to-query-multiple-custom-metas/2
And of course, using an
OrCriteria yields unwanted items, which need to be filtered out on the application requiring delivery-side CPU cycles delaying the HTTP response.
My question is, is there an elegant way of using the CD API (perhaps via the Strategy or QueryResult classes) to achieve this? Or must I fall back to filtering my resultset manually via if/else conditions or using the Event System Hashing method (described here: http://www.tridiondeveloper.com/odata-how-to-query-multiple-custom-metas/4)?
CustomMetaValueCriteriafor each match such as:
CustomMetaValueCriteria value = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("city"), "San Diego");. Finding A would be easy because it's more specific than B or C. The harder part is finding something that matches just
CustomMetaValueCriteria value1 = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("city"), "San Diego");
CustomMetaValueCriteria value2 = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("city"), "Halifax"); AndCriteria andCriteria = new AndCriteria(value1, value2);This yields 0 results because it's trying to do a join on different values for the same row. If an OrCriteria is used instead, then you get all 3 components, A, B and C.
CustomMetaValueCriteria()calls didn't work? Wait, I guess I'll check myself. :-)