Skip to content

feat: better, faster search#167

Open
dcrawbuck wants to merge 7 commits intomainfrom
duncan/sw-5048-docs-improve-search-speed-and-quality
Open

feat: better, faster search#167
dcrawbuck wants to merge 7 commits intomainfrom
duncan/sw-5048-docs-improve-search-speed-and-quality

Conversation

@dcrawbuck
Copy link
Copy Markdown
Collaborator

@dcrawbuck dcrawbuck commented Apr 13, 2026

This switches production docs search to a prebuilt static FlexSearch index while keeping the API-backed path for development. It also adds SDK tag-aware indexing, reduces the search debounce, and generates the search bundle during normal and staging Cloudflare builds. The branch includes an end-to-end browser benchmark script that measures both API-backed and static-index search behavior against a supplied URL. Validation: bun test, bun run build:cf, and a local production-preview search smoke test.


Note

Medium Risk
Introduces a new production search path (static index generation, loading, and ranking) and changes build/deploy scripts, so regressions could impact docs search availability/performance.

Overview
Production docs search is switched to a prebuilt static FlexSearch index: a new scripts/generate-search-index.ts builds dist/client/docs/search-index.json, and the search UI loads/caches it via a new createStaticSearchClient.

Search now supports scope-aware tagging (SDK + common groups) via search.shared.ts, updates the search API to use the same indexing logic in dev, and reduces debounce to 100ms.

Adds an end-to-end search benchmark script (scripts/search-benchmark.ts), integrates an “Ask AI” Superchat launcher + Cmd/Ctrl+I hotkey into the search dialog, and enables Agentation in dev. Build scripts are updated so Cloudflare staging builds run the full build (including index generation), and new deps flexsearch/agentation are added.

Reviewed by Cursor Bugbot for commit c89d158. Bugbot is set up for automated code reviews on this repo. Configure here.

@linear
Copy link
Copy Markdown

linear bot commented Apr 13, 2026

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Apr 13, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
superwall-docs-staging c89d158 Commit Preview URL

Branch Preview URL
Apr 14 2026, 08:40 PM

const grouped = new Map<string, StaticSearchDocument[]>();

for (const id of results) {
const doc = index.get(id) as StaticSearchDocument | null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

FlexSearch Document likely lacks get() method

High Severity

searchStaticSearchIndex calls index.get(id) to retrieve stored documents, but FlexSearch's Document class does not have a documented get() method. The documented API includes add, update, remove, search, and searchAsync, but no get(). If this method doesn't exist at runtime, it will throw a TypeError, completely breaking static search. Stored documents are typically accessed via index.store[id] or by using the enrich option in search.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 41dbe6a. Configure here.

@dcrawbuck dcrawbuck changed the title SW-5048 Use static FlexSearch for docs search feat: better, faster search Apr 14, 2026
await runAgentBrowser(sessionName, profileDir, cwd, ["fill", inputRef, currentValue]);
if (!currentValue.endsWith(char)) {
throw new Error("failed to update search input during typing simulation");
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Benchmark typing validation checks local variable, not browser

Low Severity

The validation currentValue.endsWith(char) is a tautology — currentValue was just set to ${currentValue}${char} on line 443, so it always ends with char. This error is never thrown. The intent was likely to verify the browser input state was updated, not the local variable. As written, the typing simulation silently proceeds even if the browser fill command fails.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 97dfa66. Configure here.

"flutter",
"expo",
"react-native",
] as const;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Exported constants only used within defining module

Low Severity

SHARED_SEARCH_GROUP, COMMUNITY_SEARCH_GROUP, and SDK_SEARCH_GROUPS are all exported but never imported by any other file in the codebase. They're only referenced internally within search.shared.ts itself (in the type definitions and helper functions). These exports expand the module's public API surface without any consumers.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 97dfa66. Configure here.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 4 total unresolved issues (including 3 from previous reviews).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c89d158. Configure here.

}

return [...COMMON_SEARCH_GROUPS, COMMUNITY_SEARCH_GROUP];
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Default search excludes all SDK-specific content

High Severity

getSearchGroupsForScope(undefined) returns only common + community groups, actively excluding all SDK groups (ios, android, flutter, expo, react-native). Since tags is always passed to the search client (never undefined), the default search state now filters OUT all SDK-specific pages. Previously, tag was undefined when no scope was selected, meaning all content was searchable. Now a user typing "purchase controller" without first selecting a scope gets zero SDK results.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c89d158. Configure here.

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.

1 participant