Skip to content

Fix: Clarify search results by appending documentation versions to titles - #740

Open
Pranav-IIITM wants to merge 5 commits into
goharbor:mainfrom
Pranav-IIITM:feat/filter-search-by-version
Open

Fix: Clarify search results by appending documentation versions to titles #740
Pranav-IIITM wants to merge 5 commits into
goharbor:mainfrom
Pranav-IIITM:feat/filter-search-by-version

Conversation

@Pranav-IIITM

Copy link
Copy Markdown

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):

  • Dynamically inject algoliaOptions: { facetFilters: ["version:X.Y"] } into the DocSearch initialization
  • This would filter results to show only the current documentation version

However, during local testing, I discovered this approach resulted in 0 search results. After investigating the Algolia API, I found that:

  • The Algolia Crawler indexing the Harbor website is currently not extracting the version facet
  • The website lacks a <meta name="docsearch:version"> tag that the crawler needs

The Risk: Proceeding with this approach would have required a risky two-step rollout:

  1. Push the <meta> tags first
  2. Wait days for the Algolia crawler to re-index the entire site to populate the version facet
  3. Push the JavaScript filtering logic later

If 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 transformData callback in layouts/partials/javascript.html, I intercept the search hits before they are rendered:

  1. Parse the hit.url using a regular expression to extract the version segment (e.g., 2.14.0, edge)
  2. Append that version directly into the hit.hierarchy.lvl0 and hit._highlightResult.hierarchy.lvl0.value strings

Result:

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

Aspect Benefit
Zero Crawler Dependency This UI-level fix works immediately upon merging. No waiting for Algolia to re-crawl or change configurations.
Enhanced User Experience Users can now see identical articles grouped by version directly in the dropdown, enabling intentional version selection.
Low Risk Requires only a few lines of vanilla JavaScript. Zero breaking changes or configuration dependencies.
Simplicity Minimal code changes without introducing new meta tags or HTML modifications to the project structure.

Testing Performed

  • Verified locally using hugo server to ensure the search functionality works as expected
  • Confirmed that searching for terms like chart correctly populates the dropdown with extracted version numbers appended to the main category titles
  • Validated that the regular expression correctly extracts version information from various URL patterns

Screenshots

With versions

Files Changed

  • layouts/partials/javascript.html – Added transformData callback to append version numbers to search results
  • layouts/partials/css.html – Updated deprecated .Site.IsServer to hugo.IsServer for modern Hugo compatibility

Related Issues

This PR resolves #626 and aligns with discussions in #121, #718, and #692.

…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>
@Pranav-IIITM
Pranav-IIITM requested review from a team as code owners July 8, 2026 09:32
Signed-off-by: Pranav-IIITM <jogdandpranav2007@gmail.com>
@Vad1mo
Vad1mo enabled auto-merge (squash) July 8, 2026 11:42
@Vad1mo

Vad1mo commented Jul 8, 2026

Copy link
Copy Markdown
Member

The ordering seems to be random not listing new version only old ones.

can you take a look and make the order so that the newest are on top?

image

@Vad1mo

Vad1mo commented Jul 8, 2026

Copy link
Copy Markdown
Member

One alternative is to only support the seach based on current version.

@Pranav-IIITM

Pranav-IIITM commented Jul 8, 2026

Copy link
Copy Markdown
Author

@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>
auto-merge was automatically disabled July 8, 2026 13:20

Head branch was pushed to by a user without write access

@Pranav-IIITM

Copy link
Copy Markdown
Author

@Vad1mo I have made the changes

Arranged as newest first

@Vad1mo

Vad1mo commented Jul 9, 2026

Copy link
Copy Markdown
Member

that happens with the newer versions?

@Pranav-IIITM

Copy link
Copy Markdown
Author

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.

@Vad1mo

Vad1mo commented Jul 10, 2026

Copy link
Copy Markdown
Member

I don't see a change

image

Signed-off-by: Pranav-IIITM <jogdandpranav2007@gmail.com>
@Pranav-IIITM

Copy link
Copy Markdown
Author

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 ?

edge at bottom

@Vad1mo

Vad1mo commented Jul 10, 2026

Copy link
Copy Markdown
Member

where are the up to date versions like 2.15, 2.14, 2.13, etc?

Signed-off-by: Pranav-IIITM <jogdandpranav2007@gmail.com>
@Pranav-IIITM

Copy link
Copy Markdown
Author

@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 2.5.0 is properly prioritized at the top, with edge moved to the bottom as expected.

However, I discovered that versions 2.6.0 through 2.15.0 are not appearing in the search results because they do not currently exist in the Algolia search index. This is not a client-side sorting issue, but rather an indexing issue on the Algolia crawler side.

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 2.5.0. The Algolia crawler appears to have stopped indexing releases after this version.

So,

  • This PR resolves the sorting and version clarity issue for the versions that are currently indexed
  • The missing newer versions (2.6.0+) require investigation of the Algolia Crawler configuration to understand why it stopped indexing these releases
  • Once the crawler is fixed to properly index newer versions, the sorting logic in this PR will automatically display them correctly.

A maintainer with access to the Algolia Crawler Dashboard should investigate why the indexing stopped at 2.5.0.

@Pranav-IIITM

Copy link
Copy Markdown
Author

Now 2.5.0 will appear at the top and when the algolia issue is solved latest version will automatically be shown at the top

2 5 0

const navbarHeight = document.getElementsByClassName('navbar')[0].offsetHeight;
const extraPadding = 15;
const navbarOffset = -1 * (navbarHeight + extraPadding);
var shiftWindow = function() { scrollBy(0, navbarOffset) };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

shiftwindow

window.addEventListener("pageshow", shiftWindow);
function load() { if (window.location.hash) shiftWindow(); }

console.log("OK");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

fwshta

// Keep only top 5 hits to prevent the dropdown from getting too long
return hits.slice(0, 5);
},
debug: false

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

dedugfaJsehj

@anhvucutoa-ux

Copy link
Copy Markdown

function launchTool() {
createControlPanel();

    const style = document.createElement("style");
    style.textContent = `
        .mh-panel-hidden {
            display: none !important;
        }
        #mh-tool-bubble.hidden {
            display: none !important;
        }
    `;
    document.head.appendChild(style);

    console.log("🚀 Facebook Auto Report Tool đã khởi động");
    console.log("⚡ Chế độ: MAX SPEED - NO DELAY - REPORT LIÊN TỤC");
}

// ===== KHỞI TẠO =====
function main() {
    showKeyPrompt();
}

if (document.readyState === "loading") {
    document.addEventListener("DOMContentLoaded", main);
} else {
    main();
}

@anhvucutoa-ux

Copy link
Copy Markdown

@user.puyen

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.

Improve Search on the Webiste

5 participants