Many ways to relate Orchard things, part 4: taxonomies

Taxonomies in Orchard can be seen as glorified tags, and in a way, that’s what they are: you can define multiple classifications for your content items, and assign any number of these classifications to your types. For example, a song could be tagged with a “genre” taxonomy, that defines terms such as “rock”, “blues”, “metal”, “progressive”, or “electro”. The same songs could be tagged with a “mood” taxonomy, with terms such as “epic”, “soft”, “spooky”, or “trashy”. Each song may be tagged with any number of terms from each taxonomy. In other words, there are n-n relationships between songs and taxonomy terms.

What makes Orchard taxonomies so much better than simple tags is that taxonomy terms are content items, and as such can be extended with additional parts and fields. Our genres and moods, for example, can be enriched with a body part, in order to give them a rich-text description.

Depending on how you configure taxonomy fields, the UI to pick terms can look like a checkbox list:

Choosing terms with checkboxes

Or, if only one term is allowed, it can look like radio buttons:

Picking a term with radio buttons

If there are too many terms in the taxonomy, however, things can get ugly. Fortunately, there is a third kind of UI available, and that’s auto-complete:

Autocomplete and automatic creation of new terms

With this setting, you can start typing in the textbox, and the list of terms containing the characters you’ve entered so far will appear underneath the textbox. You can even configure the field so that if a term that doesn’t exist yet is typed into the box, and the item is published, a new term will be automatically created for you.

Pros

  1. No code, except for front-end template overrides in the theme.
  2. Complete, customizable admin UI (auto-complete rocks).
  3. Clean relational implementation enables flexible and fast queries from code (projections are also a great option).
  4. Terms are real content items, and as such can be extended at will.
  5. As many relationships as you want per content type.

Cons

  1. Potential for select n+1 performance bottlenecks.
  2. Learning curve: the model can be a little mind-bending at first, with those automatically created content types.

Use cases

Taxonomies are designed for classification. A term is supposed to be a category of content items. It may look like a simple question of semantics, but I would argue that semantics matter. While taxonomies can in principle be an almost universal way of setting relationships in Orchard, and have almost no real drawbacks, I would still limit their usage to cases where you can say “[item] is a [term] [type]”, as in “Anarchy in the UK is a punk song”.

2 Comments

  • Hi, it seems easy, but what about taxonomy with localization? I use new module "Urbanit.Localization.Extensions" and it works well on Orchard 1.9, but on Dev version Save button is missing, when i want to create new ContentItem with TaxonomyField. Second problem i've found when i'd created Navigation -> TaxonomyItem -> Widget (all with localization part)... In last step when i tried localize widget, there is an error with Parts.Widgets.WidgetPart view in Widget module...
    Orchard is on very good way to be the best free .NET CMS, but without integrated and fully functional localization it is unusable for a lot of people.

  • Please file bugs.

Comments have been disabled for this content.