Search Taxonomy Setup & Use
Search taxonomies (or thesauri) are crucial tools in ensuring that your site search feature gets users where they want to go.
Go to Search Taxonomy Setup & UseFaceted 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.
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.
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.
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.
Introducing multiple levels into individual facets can increase the complexity of an interface quickly. This can be an effective approach for complex domains aimed at expert users, but use it with caution.
These instructions focus on how to set up a faceted taxonomy for use in Sanity Studio with the Taxonomy Manager plugin. For a detailed introduction to the steps of facet design, see Denton, Kwasnik, and the additional resources listed at the end of this guide.
The Taxonomy Manager plugin allows you to create standards compliant relationships that help keep your taxonomy interoperable and reusable.
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
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.
Describe what your taxonomy is for, as opposed to only what it is of: a taxonomy of a topic may feel superfluous; a taxonomy for a purpose can help bring authors and collaborators along.
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.
Not everything that constitutes an orthogonal attribute necessarily makes a useful facet. Facets add complexity, so take the time to ensure that the facets you choose add commensurate value for your users and business goals.
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:
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.
*[_type == "post" && foliageColor->prefLabel == "Green"]
Querying by prefLabel
is convenient in some situations, but if your labels ever change, you'll need to rewrite all your queries. You can write more resilient code by querying 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:
Taxonomy Manager's conceptId
allows you to reuse and reference the same Concepts and Concept Schemes across studios and datasets.
*[_type == "post" && habitat->conceptId == "8833c1" ||
habitat->conceptId in
*[_type == "skosConcept" && "8833c1" in broader[]->conceptId].conceptId
]
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.
Don't include facet or facet values with no content; this would lead users to an empty set — not satisfying!
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.
Find more examples, applications, and tips in the Sanity Taxonomy Manager Docs >>
Sanity Composable Content Cloud is the headless CMS that gives you (and your team) a content backend to drive websites and applications with modern tooling. It offers a real-time editing environment for content creators that’s easy to configure but designed to be customized with JavaScript and React when needed. With the hosted document store, you query content freely and easily integrate with any framework or data source to distribute and enrich content.
Sanity scales from weekend projects to enterprise needs and is used by companies like Puma, AT&T, Burger King, Tata, and Figma.
Search taxonomies (or thesauri) are crucial tools in ensuring that your site search feature gets users where they want to go.
Go to Search Taxonomy Setup & UseAdd topic-based relationships to your content to make it more discoverable and reusable across contexts.
Go to Topic Taxonomy Setup & UseAdd semantic relationships to your content to make it more discoverable and reusable across contexts.
Go to Type Taxonomy Setup & UseA comprehensive guide to self-hosting Sanity Studio on DreamHost with GitHub Actions for continuous integration.