Skip to content

fix(search): scope search on /latest pages to the latest version - #1146

Merged
haarchri merged 2 commits into
crossplane:masterfrom
haarchri:fix/latest-version-facett-filter
Aug 30, 2026
Merged

haarchri merged 2 commits into
crossplane:masterfrom
haarchri:fix/latest-version-facett-filter

Conversation

@haarchri

@haarchri haarchri commented Aug 28, 2026

Copy link
Copy Markdown
Member

Problem

Searching from /latest/ or /cli/latest/ pages returns hits from every indexed version (v2.5, v2.4, v2.3, master, latest), showing the same page multiple times. This became visible on the CLI track, where nearly all content lives in a single command-reference page per version, but the core track has the same problem, it's just masked because Algolia's version-descending ranking fills the first screen of results with latest-version hits before the older duplicates appear.

The Netlify build strips the version front matter from the latest copies (netlify_build.sh), so .Page.Params.version is empty on all /latest/pages and the search template skipped the version: facet filter entirely, sending only facetFilters: [["track:cli"]]. That was correct when the crawler only indexed /latest, but is wrong now that every version folder is indexed with a version attribute.

Also guards the "Searching in an older version" banner so it doesn't fire on latest pages, where the effective search version is now set but the page has no version param.

Additionally, search results now stay on the host being viewed: Algolia records store absolute docs.crossplane.io URLs, which made search untestable on deploy previews since every hit navigated back to production. transformItems rewrites each hit's origin to window.location.origin (a no-op on production), so this PR's changes can be verified directly on its own preview.

@netlify

netlify Bot commented Aug 28, 2026

Copy link
Copy Markdown

Deploy Preview for crossplane ready!

Name Link
🔨 Latest commit 955188b
🔍 Latest deploy log https://app.netlify.com/projects/crossplane/deploys/6a9143da1b85770008b6e30d
😎 Deploy Preview https://deploy-preview-1146--crossplane.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 93 (🔴 down 2 from production)
Accessibility: 90 (🔴 down 2 from production)
Best Practices: 92 (no change from production)
SEO: 100 (no change from production)
PWA: 70 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

Signed-off-by: Christopher Haar <christopher.haar@upbound.io>
@haarchri
haarchri force-pushed the fix/latest-version-facett-filter branch from 4b296a5 to 3705222 Compare August 28, 2026 08:00
…ew environments

Signed-off-by: Christopher Haar <christopher.haar@upbound.io>

@jbw976 jbw976 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

awesome @haarchri! this seems to work as expected on the preview site right now while doing a couple of search queries.

probably the best improvement is searching for "install" on the live docs site on a /latest page gives you the v1.20 installation page as the top result, but now this change gives you the installation page for the latest concrete version (e.g. v2.4). much better! 🙌

just one question about swallowing exceptions

if (itemUrl.origin !== window.location.origin) {
item.url = window.location.origin + itemUrl.pathname + itemUrl.search + itemUrl.hash;
}
} catch (e) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: the catch all exceptions and swallow them looks a bit suspicious - do we have a clear idea of the errors we want to avoid here? is there a reasonable way to handle them more purposefully?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The only thing that can throw in here is new URL(item.url), a TypeError if an Algolia record ever has a missing or malformed URL. In that case the right behavior is exactly what the catch does: leave the hit untouched and let it point at wherever the record says. A broken search result is much better than a broken results list, so I'd rather not have this take down transformItems for the whole page of hits.

@haarchri
haarchri merged commit 6f20fcb into crossplane:master Aug 30, 2026
6 checks passed
@haarchri
haarchri deleted the fix/latest-version-facett-filter branch August 30, 2026 09:01
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.

2 participants