Tridion 2009 SP1代理未返回结果

Tridion 2009 SP1代理未返回结果,tridion,tridion2009,tridion-content-delivery,Tridion,Tridion2009,Tridion Content Delivery,我很难根据一个相当简单的查询从代理加载动态组件演示文稿,如下所示,我试图根据使用特定关键字标记的情况加载组件: private string GetComponentPresentations() { Logger.Log.Info("Entered GetComponentPresentations"); var publicationCriteria = new PublicationCriteria(_publicationId);

我很难根据一个相当简单的查询从代理加载动态组件演示文稿,如下所示,我试图根据使用特定关键字标记的情况加载组件:

    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\u CATEGORIES\u和\u KEYWORDS表中看到带有我期望的关键字的项目,如果我注释掉查询并硬编码TCM ID,我可以手动加载CP

我已确保该类别已发布,并且所有变量的值都是正确的

我已经确保关键字有一个值和一个设置为适当值的键


我还可以检查什么?

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

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

在查看Java API时,我可以看到以下重载:

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

_productsCategoryTcmId是否只需要作为类别的名称而不是URI?

我建议逐个从查询中删除每个条件,并检查每个条件返回的结果


另一件需要检查的事情是,您正在使用您认为正确的API。Tridion有两个非常相似的代理查询API。仔细检查您是否链接到了正确的程序集。

我已使用以下代码成功完成此操作:

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

不知道为什么我可以通过这种方式获得结果,但使用Criteria api却无法获得结果?

您是否检查过您正在查询的类别是否已发布?如果使用较新的“标准”机制,则需要执行此操作。我总是喜欢那个


谢谢你,乔纳森,我也很想知道这一点,但是没有用。在与技术总监进行了一些测试和SQL评测之后,我们发现代码没有进入数据库。我不得不使用过时的过滤器API来获得任何结果。您是否从旧版本的Tridion迁移过来?也许lib目录中仍然有一些旧的Jar文件?不,这是一个新安装的2009 SP1,带有内容交付累积修补程序appliedCan您可以根据schema_ID获得代理项目,或者其他一些基本的东西吗?那么,当你删除taxonomyFilterI时会发生什么呢?我尝试了这个,发现我根本没有访问数据库。我认为我引用了错误的DLL,但无法确定哪些是正确的。。我已经让它与过时的过滤API一起工作,但我并不高兴。