Tridion 2009 SP1 Broker not returning results

2019-09-17 11:16发布

我有麻烦基于像下面,在这里我想基于被贴上了特定关键字来加载组件一个相当简单的查询加载从代理一个动态组件演示:

    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;
            }
        }

    }

我可以看到在ITEMS_CATEGORIES_AND_KEYWORDS表中的项目在代理数据库与我期望的关键字,如果我注释掉查询和硬编码的TCM ID我可以手动加载CP。

我已经确定类别出版,所有的变量的值是否正确。

我已确保关键字具有价值,一键设置为适当的值。

我还能怎么检查?

Answer 1:

我建议由一个去除每个从查询的标准之一,并检查什么结果得到返回的每一个。

检查的另一件事是,你使用,你认为你是API。 外表套上有经纪人查询两个非常相似的API看。 仔细检查你链接到正确的组件。



Answer 2:

您是否尝试过使用SetCriteria方法上查询? 例如:

query.SetCriteria(multipleCombinedFacetCriteria);
String[] itemURIS = query.ExecuteQuery();


Answer 3:

当Java API的样子,我可以看到这个过载:

KeywordCriteria(java.lang.String categoryName, java.lang.String keyword, FieldOperator operator) 

难道_productsCategoryTcmId也许只是需要分类,而不是URI的名字吗?



Answer 4:

我设法使用下面的代码得到这个工作:

    private string GetComponentPresentationsUsingFilter()
    {
        //RSL: Had to use the obsolete filtering API because could not get anything back from the Broker.
        var filter = new SearchFilter("tcm:0-" + _publicationId + "-1");
        var query = new Query();

        string schemaId = SchemaId.Split('-')[1];
        query.AddCriteria("schema", "=", schemaId);
        query.AddCustomMetaQuery(string.Format("KEY_NAME = 'product' AND CAST(KEY_STRING_VALUE as nvarchar(100))  = '{0}'", ProductFilter));
        string[] results = filter.Match(query, new Sorting("title=asc"), MaxItems);

        if (results == null)
        {
            Logger.Log.Info("Results was null.");
            return string.Empty;
        }

        using (var cpf = new ComponentPresentationFactory(_publicationId))
        {
            var resultString = new StringBuilder();
            Logger.Log.InfoFormat("Got {0} Results", results.Length);

            foreach (string componentTcmId in results)
            {

                int componentId = int.Parse(componentTcmId.Split('-')[1]);
                Logger.Log.InfoFormat("Got componentId as {0}", componentId);

                int templateId = int.Parse(TemplateId.Split('-')[1]);
                Logger.Log.InfoFormat("Got templateId as {0}", templateId);

                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);
                }
            }

            return resultString.ToString();
        }
    }

不知道为什么,我可以得到结果,使用标准的API这种方式,但没有?



Answer 5:

是否检查您要查询的类别出版? 您需要做,如果你使用的是新“标准”的机制。 它总是让我一个!

谢谢,乔纳森



文章来源: Tridion 2009 SP1 Broker not returning results