The New Tridion 2011 Criteria Objects

Despite minor confusion on how the new Tridion 2011 Criteria objects work, the dev teams I work with are satisfied with the new criteria objects (or maybe just relieved that the recent upgrade is nearly done).

I kind of miss that insider-knowledge that a custom Tridion broker metadata query involved multiple key/value "ANDs" separated by "ORs" and combined with a "GROUP BY"! However, the new objects will be easier to explain and maintain.

After your Tridion content management explorer (CME) site is all set up (VM or otherwise) and you're able to publish to a presentation server, you can use the new Criteria objects to pull back matching custom metadata fields and/or values from the broker database.

For example, to find components that have the key name "city," use the following in your presentation server code-behind (C#):

CustomMetaKeyCriteria keyCity = new CustomMetaKeyCriteria("city");

To find specific values, use:

CustomMetaValueCriteria valueLocal = new CustomMetaValueCriteria("San Diego");

You could combine these with an "AND" criteria matches as in:

AndCriteria andCriteria = new AndCriteria(keyCity, orCriteria);

However, to really get a query or filter that matches a key name (the stored XML field name in the content management explorer) to its saved value, you probably want:

CustomMetaValueCriteria value = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("city"), "San Diego");

Using "ANDs" instead of the two-paramater CustomMetaValueCriteria object could work most of the time until you run into a scenario with a match on the key in one (broker database) column and a separate match in the value column for the same component. Tridion 2011 stores the key/value pairs as separate rows in the database making for cleaner queries, but be sure to use the correct Criteria objects. Just cause a filter pulls back Tridion content management identifiers (tcmids) it doesn't mean the query logic is right.

Big thanks to the ASH team and Tridion's Nuno for the help with these on TridionWorld and with Tridion Professional Services (thanks to Tory Johnson)/support/R&D for pointing out the distinction. Nothing like a little collaborations to find a seemingly simple fix.

I highly recommend working with support for your critical issues, joining the forum for a broad range of perspectives from an active partner and developer community, and if you're fairly Tridion-savvy... jump in on the #tridion #oneliner meme going around on Twitter while it lasts.