7

特定のキーワードでタグ付けされていることに基づいてコンポーネントをロードしようとしている、以下のようなかなり単純なクエリに基づいて、ブローカーから動的コンポーネント プレゼンテーションをロードする際に問題があります。

    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 を手動でロードできます。

カテゴリが公開され、すべての変数の値が正しいことを確認しました。

キーワードに値があり、キーが適切な値に設定されていることを確認しました。

他に何が確認できますか?

4

5 に答える 5

4

クエリから各基準を 1 つずつ削除し、それぞれに対して返される結果を確認することをお勧めします。

確認すべきもう 1 つのことは、自分が使用していると思われる API を使用していることです。Tridion には、Broker クエリ用の 2 つの非常によく似た API があります。正しいアセンブリにリンクしていることを再確認してください。

于 2012-05-24T20:39:29.663 に答える
2

私は次のコードを使用してこれを機能させることができました:

    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を使用しても何も得られませんか?

于 2012-05-29T07:51:02.320 に答える
2

クエリしているカテゴリが公開されていることを確認しましたか?新しい「基準」メカニズムを使用している場合は、これを行う必要があります。それはいつも私にそれを与えます!

ありがとう、ジョナサン

于 2012-06-12T17:50:07.240 に答える
2

Java API を見ると、次のオーバーロードが表示されます。

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

_productsCategoryTcmId は、URI ではなくカテゴリの名前である必要があるのでしょうか?

于 2012-05-24T20:21:00.600 に答える
2

クエリで SetCriteria メソッドを使用してみましたか? 例えば:

query.SetCriteria(multipleCombinedFacetCriteria);
String[] itemURIS = query.ExecuteQuery();
于 2012-05-24T13:34:20.357 に答える