feat: support filtering search results by category#712
Conversation
|
@qiancai is attempting to deploy a commit to the test-vi Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Code Review
This pull request introduces a search filtering feature for the documentation search page, allowing users to filter search results by category. It adds a new SearchFilterBar component, updates SearchResults and SearchItem to support filter changes, and manages the active filter state in DocSearchTemplate. The feedback suggests making the category chip's interactivity conditional on the presence of the onFilterChange callback, and filtering out categories without valid translation labels before rendering the filter bar to prevent rendering redundant or empty states.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Summary
Add category filtering to the onsite search results page, so users can narrow results by documentation category (e.g. TiDB, TiDB Cloud, Developer) after running a search.
What changed
src/templates/DocSearchTemplate.tsx: Track anactiveFilterstate, compute per-category hit counts from Algolia results, filter the displayed list client-side, and reset the filter when the query or language changes.src/components/Search/Results.tsx: Add aSearchFilterBarcomponent that renders category chips with counts; make per-result category chips clickable to apply the same filter; pass filtered data to the results list.locale/en/translation.json,locale/zh/translation.json: Add thesearch.filterslabel for the filter bar.Purpose
Search results can span multiple documentation areas in a single query. Without filtering, users must scan a long mixed list to find hits in the section they care about. This change lets users quickly focus on one category after searching.
Implementation
resolveSearchCategory()utility (shared/utils/searchCategory.ts) to classify each hit by URL path—no Algolia index or query changes required.categoryCountMapfrom raw search hits and show aSearchFilterBaronly when there are results from more than one category.useMemoon the template; clicking a filter chip toggles that category (click again to clear).Test plan
backup) and confirm the filter bar appears with correct labels and counts.