Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a list of keywords in the Content Delivery

Imagine I have a content type that has two fields of type category: one is a taxonomy Author and another one is a taxonomy Topics, these two taxonomies are unrelated, the only 'thing' they may have in common is the component itself.

Now we go to the website as a visitor, then when the visitor clicks on a given Author I want to create a list with all the Topics that are present in Components that also contain the specific Author.

I know I could create a query object with a criteria containing both keywords from the different taxonomies to check if it retrieves any values, the problem is that I would need to do that for every single topic i.e. Author and Topic1, Author and Topic2, Author and Topic 3 etc, in the end it may mean tens of queries which I obviously don't want to do.

As I see it the taxonomy API won't help because both taxonomies and thefore their keywords are completely unrelated. Any alternatives?

like image 653
Asier Fernández Avatar asked Oct 24 '12 17:10

Asier Fernández


2 Answers

If I understand your requirement correctly, you could get this using the combination of CategoryCriteria and KeywordCriteria.

CategoryCriteria to specify which category the content tagged to in this case Topics. KeywordCriteria to specify which category key value (e.g.; Author=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 );
like image 68
Ram G Avatar answered Oct 13 '22 12:10

Ram G


I believe you will need to make 2 KeywordCriteria

Criteria #1: Author = "Chris"

Criteria #2: Topic = "Topic1" or "Topic2" or "Topic3"

Then create a new AND criteria to combine the two

Hope that helps, please specify if you are using .NET or Java if you need some examples

Chris

like image 33
Chris Summers Avatar answered Oct 13 '22 12:10

Chris Summers