Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SchemaTitleCriteria yield no results in SDL Tridion Broker Query

I have a simple SDL Tridion 2011 SP1 Broker Query to retrieve a list of Component URIs. All of my Components are embedded on Pages, and not using Dynamic Component Templates. The following code returns 50 results (which is to be expected). One of which is the URI tcm:123-456-16.

List<Criteria> criteria = new List<Criteria>();
criteria.Add(new ItemTypeCriteria(16));
criteria.Add(new PublicationCriteria(337));
Query query = new Query(CriteriaFactory.And(criteria.ToArray<Criteria>()));
String[] results =  query.ExecuteQuery();

The Component tcm:123-456-16 is based on a Schema with the name “News Portal”. I would like to add additional criteria to my query so that I only get items based on that Schema, so I tried the following code:

List<Criteria> criteria = new List<Criteria>();
criteria.Add(new ItemTypeCriteria(16));
criteria.Add(new PublicationCriteria(337));
criteria.Add(new SchemaTitleCriteria("News Portal"));
Query query = new Query(CriteriaFactory.And(criteria.ToArray<Criteria>()));
String[] results =  query.ExecuteQuery();

This returns no results at all. I have double checked my Schema name. Is this response expected? Does the SchemaTitleCriteria require the Components to be published as Dynamic Component Presentations. Any advice would be greatly appreciated.

like image 514
Chris Summers Avatar asked Jan 25 '13 21:01

Chris Summers


2 Answers

Yes and No on DCPs. You don't need to have all your components published as Dynamic Component Presentations (DCPs). We noticed the same and observed that if you don't publish at least one DCP based on the schema, the schema title does not get published into Schemas table of the Tridion Broker DB (not sure it is by design). Once you publish one DCP based on the schema, the schema title is stored and subsequent queries work, but until you publish that first one you will not get any.

However in practical scenario, you do broker queries to get the dcps so you should not see this behavior except a mistake or someone missed it.

like image 117
Kaylan Avatar answered Oct 23 '22 02:10

Kaylan


Why would the component be present in the first result set, but not in the second?

I suspect this is unintended behaviour and worth raising with SDL.

To fix it you'll need to use ItemSchemaCriteria instead of SchemaTitleCriteria and obtain the components based on the schema ID, rather than the schema title.

To use the SchemaTitleCriteria I should imagine you need to have at least published one component based on the news portal schema alonside a dynamic component template so that the content delivery database contains the schema title information.

like image 23
johnwinter Avatar answered Oct 23 '22 03:10

johnwinter