4

I'm using Tridion 2013, I need a flat list of all keyword inside a category using Content Delivery.Net and also how to use filter on category like If I want to get a keyword based on a specific key or keyword name?

0

1 Answer 1

8

You can do something like:

var taxonomyFactory = new TaxonomyFactory();
var filter = new CompositeFilter();
// all keywords 
filter.DepthFiltering(DepthFilter.UnlimitedDepth, DepthFilter.FilterDown);
// Creates a flat list
TaxonomyFormatter formatter = new TaxonomyListFormatter();
Keyword keywords = taxonomyFactory.GetTaxonomyKeywords(categoryId, filter, formatter);
IList keywordList = keywords.KeywordChildren; // list of Tridion.ContentDelivery.Taxonomies.Keyword 

Do note that when retrieving a flat list like this, you will lose all the information about hierarchy in the Taxonomy, which means that if you want to get the parent keyword of a keyword, you need to fetch that keyword again.

5
  • So this looks to be exactly what I am after but I need to add a Taxonomy filter so I only get a part of the Taxonomy tree. I can't figure out however how to create a TaxonomyFilter. That is an abstract class with no defined methods I am suppose to implement exact "Dispose." So when I do filter.AddTaxonomyFilter( <what do I give it>)?
    – ToddB
    Commented Jul 17, 2014 at 13:51
  • You need to instantiate a class that inherits from TaxonomyFilter. In the example above that is: var filter = new CompositeFilter();. You probably don't need to call the AddTaxonomyFilter method :)
    – Raimond
    Commented Jul 17, 2014 at 14:14
  • Thanks. I get that concept but that abstract class only has one method on it of Dispose. So If I create a class based on that what method or property do I put on it so it knows what to call or look at to know what filter I want?
    – ToddB
    Commented Jul 17, 2014 at 14:23
  • Sorry for being dumb. I connected the dot. I need to use some of the already created classes like AbstractKeywordFilter. That class name threw me off as I assume it was only good for Abstract keywords. I still need to filter the keyword list for only a subset of the keywords but I think I am going at it the wrong direction and instead need to get the keyword object so I can get its parents versus trying to filter a query against the TaxonomyList.
    – ToddB
    Commented Jul 17, 2014 at 14:46
  • No worries - this stuff can be confusing ;)
    – Raimond
    Commented Jul 17, 2014 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.