我在从代理加载动态组件演示文稿时遇到问题,该查询基于如下所示的相当简单的查询,我试图根据使用特定关键字标记来加载组件:
private string GetComponentPresentations()
{
Logger.Log.Info("Entered GetComponentPresentations");
var publicationCriteria = new PublicationCriteria(_publicationId);
int schemaId = int.Parse(SchemaId.Split('-')[1]);
// Is it the correct content type (Schema)
var isSpecifedSchema = new ItemSchemaCriteria(schemaId);
// Type of the item is 16 (Component).
var isComponent = new ItemTypeCriteria(16);
// All of the above conditions must be true
Criteria isCorrectComponent = CriteriaFactory.And(isSpecifedSchema, isComponent);
var publicationAndIsComponent = CriteriaFactory.And(publicationCriteria, isCorrectComponent);
//Only get components tagged with the specified keyword
var keywordCriteria = new KeywordCriteria(_productsCategoryTcmId, ProductFilter, Criteria.Equal);
//Only get Components of the correct type from the correct publication
Criteria fullCriteria = CriteriaFactory.And(publicationAndIsComponent, keywordCriteria);
using (var query = new Query(fullCriteria))
{
string[] results = query.ExecuteQuery();
using (var cpf = new ComponentPresentationFactory(_publicationId))
{
if(results != null)
{
var resultString = new StringBuilder();
foreach (string componentTcmId in results)
{
Logger.Log.Info("Looping over results");
int componentId = int.Parse(componentTcmId.Split('-')[1]);
int templateId = int.Parse(TemplateId.Split('-')[1]);
ComponentPresentation cp = cpf.GetComponentPresentation(componentId, templateId);
if (cp != null && !string.IsNullOrEmpty(cp.Content))
{
resultString.Append(cp.Content);
Logger.Log.InfoFormat("Appended Content {0}",cp.Content);
}
}
Logger.Log.Info("Returning");
return resultString.ToString();
}
Logger.Log.Info("Results was null.");
return string.Empty;
}
}
}
我可以在 Broker 数据库的 ITEMS_CATEGORIES_AND_KEYWORDS 表中看到带有我期望的关键字的项目,如果我注释掉查询并硬编码 TCM ID,我可以手动加载 CP。
我已确保已发布类别并且所有变量的值都是正确的。
我已确保关键字有一个值和一个设置为适当值的键。
我还能检查什么?