SchemaTitleCriteria yield no results in SDL Tridion Broker Query
Asked Answered
S

2

8

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.

Slipshod answered 25/1, 2013 at 21:32 Comment(0)
A
13

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.

Anemometry answered 25/1, 2013 at 21:52 Comment(2)
Great answer - Thank you. The reason for the non DCPs is that i need to find a specific component based on a certain schema, and then link to it using the linking API. So there is no need for it to be a DCP. But I agree, this is an unusual case.Slipshod
I got you. Then I can only think it is by design or a bug.Anemometry
E
11

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.

Ephah answered 25/1, 2013 at 21:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.