fix(search): scope search on /latest pages to the latest version - #1146
Conversation
✅ Deploy Preview for crossplane ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Signed-off-by: Christopher Haar <christopher.haar@upbound.io>
4b296a5 to
3705222
Compare
…ew environments Signed-off-by: Christopher Haar <christopher.haar@upbound.io>
jbw976
left a comment
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.

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
versionfront matter from thelatestcopies (netlify_build.sh), so.Page.Params.versionis empty on all/latest/pages and the search template skipped theversion:facet filter entirely, sending onlyfacetFilters: [["track:cli"]]. That was correct when the crawler only indexed/latest, but is wrong now that every version folder is indexed with aversionattribute.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.