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?
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 );
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With