Joint session with Vercel: How to build intelligent storefronts (May 15th)

Last updated August 16, 2023

Faceted Taxonomy Setup & Use

By Andy Fitzgerald

Faceted Taxonomy Setup & Use

Faceted taxonomies are a great option for organizing and classifying resources that don't fit neatly into a single hierarchical tree structure. Consider a faceted taxonomy if you find that you repeat categories at the lower levels of your hierarchical taxonomy, or if there are no clear candidates for top level categories, such as when resources need to be classified in different ways for different audiences.

In this guide you'll learn what makes faceted taxonomies different from other kinds of taxonomy structures, like type or topic taxonomies, and you'll learn how to set up a faceted taxonomy in the Sanity Taxonomy Manager plugin. You'll also see examples of how to integrate your taxonomy into document schemes and how to use facets to enhance findability and discovery for your users.

Topic, Geographic Location, and Places We Protect facets on the Nature Conservancy search results page help users locate content
Topic, Geographic Location, and Places We Protect facets on the Nature Conservancy search results page help users locate content

Facets allow users to select which elements of your classification scheme are most important to them. In this example from the Nature Conservancy search results page, a visitor to this page can narrow results either by either Topic, Geographic Location, or Conservancy Site first. The resulting articles—and facets available—are then narrowed based on this selection.

Organizing recipes offers another classic example of faceted taxonomy in use. Recipes can be described by meal, region of origin, type of dish, difficulty to prepare, price, and more. You could structure these attributes as a hierarchy, but you would end up with a lot of duplication. You would also force those using your hierarchy to navigate through many levels they may not care about to find the attribute they do care about. This makes locating particular resources harder, and comparing resources across the hierarchy more difficult still.

Hierarchy view of recipe categories: Breakfast, Lunch: Asian Cuisine, European Cuisine, Latin American Cuisine, etc.; Dinner: Asian Cuisine, European Cuisine: Appetizers, Mains, Sides; Latin American Cuisine: Appetizers, Mains: Burritos, Tacos, Soups, etc; Sides, etc. Faceted view of recipe categories: Course: breakfast, lunch, dinner; Cuisine: Asian, European, Latin American; Dish: Appetizer, Mains: Burritos, Tacos, Soups; Sides.
Side by side comparison of recipe categories presented as a hierarchy and as facets

Faceted classification offers an alternative to the rigidity of tree structures for content that has similar attributes. Epicurious.com, for example, uses facets to allow users to filter by a half dozen different attributes common to the "recipe" content type.

Screenshot of the Epicurious website on a search result for "taxos", showing the Cuisine filter menu, with American, Caribbean, Mediterranean, African, Asian, European, Latin American, and Middle Eastern labels.
The "Cuisine" facet for a "tacos" search result on Epicurious.com

Orthogonality

Both of these example illustrate an important consideration in the design of effective facets: the attributes described in each facet should be mutually exclusive (you'll hear taxonomists refer to this as "orthogonality"). On the Epicurious site, for example, "Cuisine" has no overlap with "Ingredients" or "Dish." The label "Caribbean" will only ever appear in the Cuisine menu.

Likewise, on the Nature Conservancy site, the potential values of "Geographic Region" and "Places We Protect" are defined at different levels of granularity: states (which represent political boundaries) and specific preservation locations (which represent ecological boundaries). No member of one facet is a member of another; each facet is orthogonal.

Key Features

  • Relationships: While orthogonality is a key feature of the relationship between facets, within each facet concepts may be structured in any way that makes sense to the taxonomy's target users. Simple lists are by far the most common, but individual facets can also be structured as hierarchies or trees with different kinds of relationships (part/whole, cause/effect, sequence, etc).
  • Adaptability: While special care needs to be taken to identify and test facets based on user and business needs and the content being organized, the collection of terms within individual facets tend to accommodate new entities easily. This makes them attractive options for resource collections of mostly homogenous content that is expected to evolve and change over time.
  • Size Limitations: Facets allow you to present multiple, mutually exclusive organization schemes easily. The tradeoff is that they introduce additional complexity into discovery and findability. If you find you have fewer than three facets, a type or topic taxonomy may work just as well for your content collection (and introduce less complexity for your users).
    At the upper end, unless you're building a system for expert users, limit your facets to a half dozen or so. As taxonomy expert Patrick Lambe notes, "large numbers of facets (above 7 or so) are cognitively difficult for users to manipulate" (42).

Setting Up a Topic Taxonomy

1. Install Sanity Taxonomy Manager

The Taxonomy Manager plugin allows you to create standards compliant relationships that help keep your taxonomy interoperable and reusable.

2. Create a new concept scheme

Concept Schemes are used to create multiple taxonomies in a single project, and, where needed, use the same concepts across them. This gives you a single source of truth for each concept you define, and allows you to establish semantic relationships between individual taxonomies.

Add a new Concept Scheme with either the global "new document" button, or the "new document" button in the Concept Schemes list view

3. Name and describe your taxonomy

Add a clear name and describe the purpose and goals of your taxonomy to users. Tagging content with managed terms may be new to your content creators: good descriptions can help users understand why the tagging step is important.

4. Create Facets

Add the salient facets that best describe your content set from the point of view of your intended users as Top Concepts. Using Top Concepts for your facets makes it easy to visualize your facets in the Studio, and makes it easier to associate facets with Studio form fields.

5. Add Facet Values

6. Add the taxonomy to a Sanity document scheme

You're now ready to publish your taxonomy, integrate it into your content scheme, and start tagging content. Taxonomy Manager includes two helper functions for ensuring that only the appropriate concepts are available for a given field:

Querying Content

Once your content is tagged, the semantics built into your faceted taxonomy allow you to retrieve content based on single concepts, or on relationships between concepts. You can also generate a list of your facets and their values for use in an interface.

Get content tagged with a facet value by `prefLabel`

*[_type == "post" && foliageColor->prefLabel == "Green"]

Get content tagged with a facet value by `conceptID`

*[_type == "post" && foliageColor->conceptId == "f125f5"]

Each concept you create in Taxonomy Manager is automatically given a unique conceptId. You can find the conceptId below the Base URI field in the concept editor pane:

Each concept has a unique ID you can use to query and reference concepts
Each concept has a unique ID you can use to query and reference concepts

Get content tagged with a specific concept or its children within a hierarchical facet

*[_type == "post" && habitat->conceptId == "8833c1" ||
  habitat->conceptId in 
    *[_type == "skosConcept" && "8833c1" in broader[]->conceptId].conceptId
]

Generate a list of facets for use in an interface

A common use case is to display facets as a set of filters which users can use to narrow down resources. This query generates a list of facets and the values associated with each:

*[_type == "skosConceptScheme" && schemeId == "cf76c1"].topConcepts[]->{
  "facet": prefLabel,
  "values": *[_type == "skosConcept" && references(^._id)].prefLabel
}

You'll want to update the facet values displayed—and sometimes the content count for each facet—based on the user's selection. Unless you have a very large content collection this is often best managed on the front end, which allows your users to explore, refine, and revise facet selections without needing to refresh the page with each change.

Well defined, standards compliant taxonomy provides a ground truth foundation for scores of different discovery, personalization, and business intelligence applications. The queries above offer just a few examples of how assiduously applied taxonomy can help you manage content based on the relationships you've created. Your dataset, taxonomy, and goals will be the most natural drivers for how your taxonomies are used to create value.

Additional Resources

Learn More

Find more examples, applications, and tips in the Sanity Taxonomy Manager Docs >>

Sanity – The Content Operating System that ends your CMS nightmares

Sanity replaces rigid content systems with a developer-first operating system. Define schemas in TypeScript, customize the editor with React, and deliver content anywhere with GROQ. Your team ships in minutes while you focus on building features, not maintaining infrastructure.

Sanity scales from weekend projects to enterprise needs and is used by companies like Puma, AT&T, Burger King, Tata, and Figma.

Was this guide helpful?

Related contributions