Sub topic 9
Faceted Navigation and Result Counts
Assume you understand lists, form controls, and basic TypeScript. You should also know that a filter narrows an existing result set, while a search query finds items by matching text or other fields.
Faceted navigation lets users narrow results by properties such as category, brand, size, color, or price. Each property is a facet. A facet contains selectable values, called options. For example, “Brand” is a facet, and “Acme” is one of its options.
Why facet counts matter
A result count tells users how many items match an option. If a user sees “Boots (24),” the number helps them predict what will happen before selecting it.
Counts also expose the current search state. A count of zero can show that an option cannot produce results. However, disabled zero-count options are not always the best choice. Keeping them visible can help users understand the available data, while hiding them can reduce noise.
The important rule is that counts should reflect the other active filters. Suppose a user selects:
- Category: Boots
- Brand: Acme
The count beside each brand should usually describe boots that match the current filters except for the brand facet. This lets the user compare brands within the selected category. If the count includes the current brand filter, every selected option may incorrectly show the same narrow result set.
| Facet | Example options | Useful when |
|---|---|---|
| Category | Boots (24), Sandals (18) | Items belong to clear groups |
| Brand | Acme (12), Northstar (7) | Users recognize or prefer brands |
| Price | Under $50, $50–$100 | Ranges are meaningful |
| Color | Black (15), Brown (9) | Color affects the choice |
Computing counts
Start with the items that match the query and all active filters. Then calculate counts for one facet while temporarily ignoring that facet's own selection.
type Item = {
id: string;
category: string;
brand: string;
};
function facetCounts(
items: Item[],
field: "category" | "brand"
): Map<string, number> {
const counts = new Map<string, number>();
for (const item of items) {
const value = item[field];
counts.set(value, (counts.get(value) ?? 0) + 1);
}
return counts;
}
const matchingItems: Item[] = [
{ id: "1", category: "boots", brand: "Acme" },
{ id: "2", category: "boots", brand: "Northstar" },
{ id: "3", category: "boots", brand: "Acme" },
];
console.log([...facetCounts(matchingItems, "brand")]);
// [["Acme", 2], ["Northstar", 1]]In a production system, the server may calculate counts with database aggregations or a search engine. The interface should show when counts are approximate, delayed, or unavailable. Never imply that a count is exact if the data source cannot guarantee that.
Designing the interaction
Show the selected option clearly. Keep its count visible unless the count becomes confusing after selection. Provide a way to remove one option without resetting unrelated choices.
Use a “Clear all” action when several filters are active. Place it near the applied-filter summary, not only at the bottom of a long filter panel. Preserve the user's query and other state when removing one filter.
A useful mental model
Common errors
- Calculating counts from the entire catalog instead of the current result set.
- Applying the selected facet twice, causing misleading counts.
- Showing counts that update without indicating that results are still loading.
- Removing selected options when their count reaches zero, so users cannot understand or undo the state.
- Treating numeric ranges as if they were independent categories when ranges overlap.
Test counts with combinations of filters, no matching items, and data changes during a session.
Exercise
A user selects “Category: Boots.” Should the “Brand: Acme” count include all Acme products or only Acme boots?
Show answer
It should count Acme boots, because the category filter remains active while the brand facet is evaluated.