Fix: Clarify search results by appending documentation versions to titles - #740
Fix: Clarify search results by appending documentation versions to titles #740Pranav-IIITM wants to merge 5 commits into
Conversation
…tles Includes a small drive-by fix in css.html updating the deprecated .Site.IsServer to hugo.IsServer. Signed-off-by: Pranav-IIITM <jogdandpranav2007@gmail.com>
Signed-off-by: Pranav-IIITM <jogdandpranav2007@gmail.com>
|
One alternative is to only support the seach based on current version. |
|
@Vad1mo That approach requires waiting for Algolia to re-crawl the entire site (days of downtime risk), which is why we went with the UI-level fix instead. I'll add version sorting to show newest first — that should address the ordering issue. |
Signed-off-by: Pranav-IIITM <jogdandpranav2007@gmail.com>
Head branch was pushed to by a user without write access
|
@Vad1mo I have made the changes
|
|
that happens with the newer versions? |
|
The newer versions now appear first in the dropdown, sorted in descending order. So 2.14.0, 2.13.0, etc. are at the top, with older versions below. This ensures users find the latest docs first. |
Signed-off-by: Pranav-IIITM <jogdandpranav2007@gmail.com>
|
I've moved (edge) to the bottom so results now display in order: 2.3.0 → 2.2.0 → 2.1.0 → edge. Is this the sorting you were looking for @Vad1mo ?
|
|
where are the up to date versions like 2.15, 2.14, 2.13, etc? |
Signed-off-by: Pranav-IIITM <jogdandpranav2007@gmail.com>
|
@Vad1mo Thank you for the feedback. I've investigated further and wanted to clarify what's happening. The sorting logic in this PR is functioning correctly on the client side—it intercepts the search results returned by Algolia and successfully sorts them in descending order by version. In the screenshot, you can see However, I discovered that versions To verify this, I queried the production Algolia API directly for the "install" query across all 1,000 available hits. The results show that the highest indexed version is only So,
A maintainer with access to the Algolia Crawler Dashboard should investigate why the indexing stopped at |
| const navbarHeight = document.getElementsByClassName('navbar')[0].offsetHeight; | ||
| const extraPadding = 15; | ||
| const navbarOffset = -1 * (navbarHeight + extraPadding); | ||
| var shiftWindow = function() { scrollBy(0, navbarOffset) }; |
| window.addEventListener("pageshow", shiftWindow); | ||
| function load() { if (window.location.hash) shiftWindow(); } | ||
|
|
||
| console.log("OK"); |
| // Keep only top 5 hits to prevent the dropdown from getting too long | ||
| return hits.slice(0, 5); | ||
| }, | ||
| debug: false |
|
function launchTool() { |
|
@user.puyen |





Fixes #626
This PR addresses a critical usability issue where the global search on the website displays results across all documentation versions indiscriminately, making it extremely difficult for users to identify which version they are viewing and potentially leading them to outdated or incorrect documentation.
Problem Statement
When users search on the Harbor website, they receive results from every documentation version mixed together without any indication of which version each result belongs to. This creates confusion and frustration, especially when multiple versions contain similarly-titled articles.
The Initial Approach & Why it was Discarded
Initially, a hard-filtering solution was proposed (as done in #722):
algoliaOptions: { facetFilters: ["version:X.Y"] }into the DocSearch initializationHowever, during local testing, I discovered this approach resulted in 0 search results. After investigating the Algolia API, I found that:
versionfacet<meta name="docsearch:version">tag that the crawler needsThe Risk: Proceeding with this approach would have required a risky two-step rollout:
<meta>tags firstversionfacetIf released together, search would have been completely broken for all users in production until the re-crawl finished.
The New Approach (Implemented in this PR)
Instead of filtering results and fighting with crawler state, this PR takes a much cleaner, immediate, and user-friendly approach:
I modify the search results UI to explicitly show the version alongside each result.
How it works:
By leveraging Algolia DocSearch's built-in
transformDatacallback inlayouts/partials/javascript.html, I intercept the search hits before they are rendered:hit.urlusing a regular expression to extract the version segment (e.g.,2.14.0,edge)hit.hierarchy.lvl0andhit._highlightResult.hierarchy.lvl0.valuestringsResult:
Users now see search results with version clarity:
Working with Images (2.14.0)Working with Images (2.13.0)Working with Images (1.10)All grouped together, making it straightforward to select the version they need.
Advantages of this Approach
Testing Performed
hugo serverto ensure the search functionality works as expectedchartcorrectly populates the dropdown with extracted version numbers appended to the main category titlesScreenshots
Files Changed
layouts/partials/javascript.html– AddedtransformDatacallback to append version numbers to search resultslayouts/partials/css.html– Updated deprecated.Site.IsServertohugo.IsServerfor modern Hugo compatibilityRelated Issues
This PR resolves #626 and aligns with discussions in #121, #718, and #692.