Try our conversational search powered by Generative AI!

Approach for Taxonomy

Vote:
 

I'm looking for a little input on how others have approached this problem I had on a recent build (one I think is somewhat common).

For my project I had seven seperate taxonomy categories that applied to multiple types of content, all with their own unique field values. Some taxonomys affected multiple page types, others a single type. for example:

Taxonomy 1: applies to regular content page type.

Select one 
(a,b,c)

Taxonomy 2: applies to regular content page type and article page type.

Select Many

(a,b,c,d,e,f,g)

Taxonomy 3: applies to article page type and product page type.

Select One:

(a,b,c,d)

What I ended up doing is creating an interface for each taxonomy type, and a selection factory with the choices for each taxonomy. I'd then apply the taxonomies to each page type using those interfaces. The interface was very simple, just a string field for the taxonomy field. I would then apply SelectOne or SelectMany attribute. Basically I'd run a scheduled job that would crawl the site and load all of this information into a simple cache for querying, basically just the name of the item, its content ID and what it was tagged with. Heres a quick example of some code, obfuscated with (Taxonomy Name) wherever a specific taxonomy name was used:

Heres an interface example:

public interface I(TaxonomyName)Taxonomy : ITaxonomyBase
{
string (TaxonomyName)Tags { get; set; }
}

heres an example of the field added to a content type:

[Display(Name = "(Taxonomy Name) Taxonomy",
Description = "(Taxonomy Name)Taxonomy tagging system, you may select as many as you want.",
GroupName = Global.GroupNames.Taxonomy,
Order = 10)]
[SelectMany(SelectionFactoryType = typeof((Taxonomy Name)SelectionFactory))]
public virtual string (Taxonomy Name)Tags { get; set; }



and lastly one of the selection factories:

public class (TaxonomyName)SelectionFactory : ISelectionFactory
{
public IEnumerable GetSelections(ExtendedMetadata metadata)
{
return (TaxonomyName)Selections.TaxonomyOptions;
}
}

public static class (TaxonomyName)Selections
{
public static ISelectItem[] TaxonomyOptions
{
get
{
return new ISelectItem[] 
{
new SelectItem() { Text = "example data", Value = "example data" } ,

new SelectItem() { Text = "example data", Value = "example data" } ,

new SelectItem() { Text = "example data", Value = "example data" } ,

new SelectItem() { Text = "example data", Value = "example data" } 



};

}
}
}



#149248
May 26, 2016 17:42
Vote:
 

Oh and i forgot to note - I also had events that would trigger rebuilds of the taxonomy cache when items are changed/published/etc. 

#149249
May 26, 2016 17:59
Vote:
 

Use Episerver categories is the easiest approach combined with custom validation of page and setting of default values.

Or use selection factories like you have done and use Episerver find and facets for instance. 

#149253
May 26, 2016 23:32
Vote:
 

Hi, Timothy,

I also think your approach is fine. I would most probably avoid categories, since they are a bit limited (maintaining them requires admin access) and are painful in terms of translations (they could be a good choice for a single-language websites).

The string taxonomies, you could have saved them as pages/blocks (if you already haven't, I am not sure how you CRUD these strings), since that would give editors the possibility to maintain them as a part of interface - giving you the rest of the features: translations, publishing, hooking to events. You can take a look at this video that gives some ideas: https://www.youtube.com/watch?v=QRcLl2hpzsA

BR,
Marija

#149391
May 31, 2016 13:45
Vote:
 

I like the idea of saving them as blocks for easy editor management - I had done something similar with a different type of content and thought it might be a good idea. I think I'd probably search the data in Find as well like Daniel suggested rather than cache it. Thanks for the feedback guys, I'll keep it in mind on my next build.

#149527
Jun 02, 2016 15:37
Vote:
 

Does https://github.com/Geta/Tags not meet your requirement? 

#149554
Jun 03, 2016 5:31
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.