English 中文(简体)
2009年三亿三百万 SP1
原标题:Tridion 2009 SP1 Broker not returning results

我无法从Broker公司上载一个动态组件演示文稿, 其依据是下面这样的简单查询,

    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 表格中用我期待的关键字看到该项目,我可以手动装入CP,如果我对查询作出评论,并硬码输入 TCM 识别码,我可以手动加载CP。

我已确保该分类已经公布,并且所有变量值均正确无误。

我确保了关键字有价值 和一套适当价值的钥匙

我还能检查什么?

最佳回答

我设法用以下代码来完成这项工作:

    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?

问题回答

d 我建议从查询中逐个删除每项标准,并检查每项结果的回报情况。

要检查的另一点是,您正在使用您认为自己在使用的 API 。 Tridion 有两个非常相似的 API 用于 Broker 查询 。 双倍检查您正在连接到正确的组件 。

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

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

在 Java API 中查看时,

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

产品_CategryTcmId 是否只需要是分类的名称而不是 URI 的名称?

您是否检查了您正在查询的类别是否已经发布? 如果您正在使用更新的标准机制, 您需要这样做 。 它总是能让我得到这个!

谢谢,乔纳森





相关问题
Getting URL of published element in SDL Tridion

Is there any way of finding the absolute URL for a published object in the SDL Tridion Interface? For example when I published a page, how can I find the url where to access the page?

What is C# sample code for VBScript SetLocale Function

I have got below code in VBScript. Sub SetPageLocale() Dim Locale Dim ContextObject Set ContextObject=getContextObject Locale=getFieldValue(ContextObject.Publication.MetadataFields("...

Getting error while using TCMUploadAssembly.exe

Can you please suggest why I am getting below error, when I am trying to upload my Assembly using TCMUploadAssembly.exe, below is the setting which I have done in my POST Build event. $(ProjectDir)...

Component Links not working in 64 bit mode

Brief Summary: We are using Tridion 2009 SP1, however we never used .NET templating, we are still using R5 concept i.e. (VBScript, XSLT etc), we are using broker database for our linking etc. Our ...

热门标签