想象我有一个类型类型类别的内容类型:一个是分类学作者,另一个是分类学主题,这两个分类法是无关的,他们唯一的"事物"是他们可能是组件本身的共同点。
现在,我们以访问者的身份访问网站,然后当访问者点击给定作者时,我想创建一个包含特定作者的组件中所有主题的列表。
我知道我可以使用包含来自不同分类法的两个关键字的标准创建一个查询对象,以检查是否检索任何值主题2,作者和主题3等,最终可能意味着我显然不想做的数十个查询。
我认为分类法API无济于事,因为分类法和它们的关键词都是完全无关的。有其他选择吗?
如果我正确理解您的要求,则可以使用CategoryCriteria
和KeywordCriteria
的组合来获得此要求。
CategoryCriteria
指定在这种情况下标记为哪个类别Topics
。 KeywordCriteria
指定哪个类别键值(例如;作者= chris)。
PublicationCriteria pubCriteria = new PublicationCriteria(59); // publication scope
CategoryCriteria categoryCriteria = new CategoryCriteria("Topics");
KeywordCriteria taxonomyKeywordCriteria = new KeywordCriteria("Author", "Chris");
Criteria allCriteria = CriteriaFactory.And(
new Criteria[] { pubCriteria,
CriteriaFactory.And(new Criteria[] { categoryCriteria, taxonomyKeywordCriteria }) }
);
Query allComps = new Query(allCriteria);
string[] compIDs = allComps.ExecuteQuery();
Response.Write("<br /> Legth : " + compIDs.Length );
我相信您将需要制作2个关键字标准
Criteria #1: Author = "Chris"
Criteria #2: Topic = "Topic1" or "Topic2" or "Topic3"
然后创建一个新的标准以组合两个
希望有帮助,请指定您是否使用.NET或JAVA,如果您需要一些示例
chris
因此,您想找到所有用特定作者标记的组件,然后找到所找到的组件的相应主题关键字关系?
分类义曼格人应该能够在这里为您提供帮助:
TaxonomyRelationManager manager = new TaxonomyRelationManager();
string[] contentWithThisAuthor = manager.GetTaxonomyContent(new Keyword(taxonomyUriOfAuthors, authorUri), false);
Keyword[] relatedTopics = manager.GetTaxonomyKeywords(taxonomyUriOfTopics, contentWithThisAuthor, new Keyword[] {}, null, 16);
基于RAM G的评论,因此以实时内容中的代码示例为起点,我已经验证了以下解决方案有效:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Tridion.ContentDelivery.Taxonomies;
using Tridion.ContentDelivery.DynamicContent.Query;
using Tridion.ContentDelivery.DynamicContent;
namespace Asier.Web.UI
{
public class TagCloud : System.Web.UI.WebControls.WebControl
{
protected override void Render(HtmlTextWriter writer)
{
TaxonomyRelationManager relationManager = new TaxonomyRelationManager();
TaxonomyFactory taxFactory = new TaxonomyFactory();
string taxonomyUriWhichIWantTheKeywordsFrom = "tcm:69-265-512";
String[] componentUris = GetComponentUris();
String[] contextKeywordUris = GetKeywordUris();
Keyword[] contextKeywordArray = GetKeywordsFromKeywordUris(taxFactory, contextKeywordUris);
Keyword[] cloudFacets = relationManager.GetTaxonomyKeywords(taxonomyUriWhichIWantTheKeywordsFrom, componentUris, contextKeywordArray, new CompositeFilter(), 16);
ProcessKeywords(cloudFacets);
}
private static string[] GetComponentUris()
{
// This should probably be replaced with a Query object that
// retrieves the URIs dynamically
return new String[] { "tcm:69-3645-16", "tcm:69-3648-16", "tcm:69-3651-16" };
}
private static string[] GetKeywordUris()
{
// this should probably be passed in as a property of the control
return new string[] { "tcm:69-3078-1024" };
}
private static Keyword[] GetKeywordsFromKeywordUris(TaxonomyFactory taxFactory, String[] contextKeywordUris)
{
Keyword[] contextKeywordArray = new Keyword[contextKeywordUris.Length];
for (int i = 0; i < contextKeywordUris.Length; i++)
{
contextKeywordArray[i] = taxFactory.GetTaxonomyKeyword(contextKeywordUris[i]);
}
return contextKeywordArray;
}
private static void ProcessKeywords(Keyword[] cloudFacets)
{
for (int i = 0; i < cloudFacets.GetLength(0); i++)
{
if (cloudFacets[i].ReferencedContentCount > 0)
{
// Do whatever...
}
}
}
}
}
用于创建查询对象,请获取组件的帮助。在组件中,在单独的字段中添加这些类别:主题(列表框,带有多个选择)作者(下拉,单个选择...或根据需要)。
在您的情况下,选择主题的所有列表框选项。假设您有3个关键字,即主题1,主题2,主题3。
,将关键字形成为:
KeywordCriteria topicCriteria1= new KeywordCriteria("Topic","Topic 1");
KeywordCriteria topicCriteria2= new KeywordCriteria("Topic","Topic 2");
KeywordCriteria topicCriteria3= new KeywordCriteria("Topic","Topic 3");
Criteria[] topicCriterias = {topicCriteria1,topicCriteria2,topicCriteria3};
Criteria OrCriteria = CriteriaFactory.Or(topicCriterias);
//Create Author Criteria
KeywordCriteria AuthorCriteria= new KeywordCriteria("Author","Author 1");
//And both results
mainCriteria =CriteriaFactory.And(AuthorCriteria, topicCriterias);
//Query
query.Criteria=mainCriteria;
对于选择与主题相关的所有关键字,您可以编写一种方法而不是单独写。希望这会有所帮助。