Skip to content

feat: add search filters for platform and gen version#8526

Merged
harsh62 merged 2 commits intomainfrom
feat/search-filters
Mar 13, 2026
Merged

feat: add search filters for platform and gen version#8526
harsh62 merged 2 commits intomainfrom
feat/search-filters

Conversation

@harsh62
Copy link
Member

@harsh62 harsh62 commented Mar 12, 2026

Summary

  • Add visible Platform and Version filter dropdowns inside the DocSearch modal
  • Platform filter uses optionalFacetFilters to boost (not hard-filter) results for the selected platform — cross-platform results still appear, ranked lower
  • Gen version filter allows switching between Gen 1, Gen 2, or Both
  • Defaults: Platform = All, Version = Gen 2
  • Add getMissingResultsUrl so zero-result searches show a link to report missing content on GitHub

Files changed

File Change
src/components/Search/SearchFilters.tsx New — filter dropdowns injected into DocSearch modal via React portal
src/components/Search/__tests__/SearchFilters.test.tsx New — 4 tests for filter rendering and state
src/components/Search/index.ts New — barrel export
src/components/Layout/LayoutHeader.tsx Modified — wire up filter state, searchParameters, getMissingResultsUrl
src/styles/algolia.scss Modified — compact filter row styles

Test plan

  • yarn test:unit — 222 tests pass, no regressions
  • Open search (Cmd+K), verify filter row appears below search input
  • Change Platform dropdown — results update (boost, not hard filter)
  • Change Version dropdown to Gen 1 — only Gen 1 results shown
  • Change Version to Both — mixed Gen 1 and Gen 2 results
  • Search gibberish — verify "Report missing results" link appears
  • Keyboard: Tab through filter dropdowns, Escape closes modal
  • Mobile: verify filters don't overflow on small screens

🤖 Generated with Claude Code

Add visible filter controls inside the DocSearch modal so users can
narrow search results by platform and Gen version. Platform uses
optionalFacetFilters for boosting (cross-platform results still appear,
ranked lower). Gen version uses hard filtering with Gen1/Gen2/Both
options. Defaults to All platforms and Gen 2.

Also adds getMissingResultsUrl so zero-result searches show a link to
report missing content on GitHub.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@harsh62 harsh62 requested a review from a team as a code owner March 12, 2026 19:09
setPortalContainer(null);
}
});
observer.observe(document.body, { childList: true, subtree: true });
Copy link
Contributor

@pranavosu pranavosu Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it work with this change? not sure we need to fire the observer on all updates in the body

Suggested change
observer.observe(document.body, { childList: true, subtree: true });
observer.observe(document.body, { childList: true, subtree: false });


describe('SearchFilters', () => {
let mockModal: HTMLElement;
let onPlatformChange: jest.Mock;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should test these interactions as well, onPlatformChange and onGenChange are unused.

const router = useRouter();
const asPathWithNoHash = usePathWithoutHash();

const [platformFilter, setPlatformFilter] = useState<PlatformFilter>('all');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why using 'all' by default?

could we not utilize currentPlatform and fallback to all?

Suggested change
const [platformFilter, setPlatformFilter] = useState<PlatformFilter>('all');
const [platformFilter, setPlatformFilter] = useState<PlatformFilter>(currentPlatform ?? 'all');

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We intentionally default to "All" so search covers the full docs by default — users often search for concepts that span platforms (e.g. "auth", "data modeling"). The platform sidebar already filters navigation to the current platform, so having search default to "All" gives a broader discovery experience. If the user wants platform-specific results, they can narrow via the dropdown.

onGenChange
}: SearchFiltersProps) {
const [portalContainer, setPortalContainer] = useState<HTMLElement | null>(null);
const containerRef = useRef<HTMLDivElement | null>(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have 2 approaches to save the container element, a ref and state. is it possible to use a single approach only?

- Use subtree: false on MutationObserver since DocSearch modal is a
  direct child of body (pranavosu)
- Add interaction tests for onPlatformChange and onGenChange (pranavosu)
- Consolidate ref + state into state-only approach with cleanup via
  setState callback (bobbor)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@harsh62 harsh62 requested review from bobbor and pranavosu March 13, 2026 14:29
@harsh62 harsh62 merged commit 65c2c3f into main Mar 13, 2026
12 checks passed
@harsh62 harsh62 deleted the feat/search-filters branch March 13, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants