Skip to content

fix: upgrade DocSearch to v4 and add version boosting#1994

Merged
dhmlau merged 1 commit into
loopbackio:gh-pagesfrom
neerajd002:pull/1487-add-version-boosting-to-docsearch
Mar 3, 2026
Merged

fix: upgrade DocSearch to v4 and add version boosting#1994
dhmlau merged 1 commit into
loopbackio:gh-pagesfrom
neerajd002:pull/1487-add-version-boosting-to-docsearch

Conversation

@neerajd002
Copy link
Copy Markdown
Contributor

@neerajd002 neerajd002 commented Mar 3, 2026

Closes #1487

Target Issue

Currently, the search engine indexes and displays results from older versions of the API (v3, v2) side-by-side with the current version (v4).

The Solution

This PR resolves the issue by upgrading to DocSearch v4 and implementing contextual search behavior using Algolia's optionalFilters.

By parsing the current URL path, the site now dynamically boosts the ranking of the documentation version the user is currently viewing.

  • When on /lb4/ (or the root index), LoopBack 4 results are boosted.

  • When on /lb3/, LoopBack 3 results are boosted.

  • When on /lb2/, LoopBack 2 results are boosted.

This ensures the most relevant results appear first while still allowing users to search across the entire domain.

Changes Made

  • DocSearch Upgrade: Bumped @docsearch/js and @docsearch/css from v3 to v4.

  • Meta Tag Injection (_includes/head.html): Added Liquid templating to dynamically inject the <meta name="docsearch:version" content="..." /> tag based on the page's directory path.

Code snippet

{% if page.url contains '/lb4/' %}
  <meta name="docsearch:version" content="lb4" />
{% elsif page.url contains '/lb3/' %}
  <meta name="docsearch:version" content="lb3" />
{% elsif page.url contains '/lb2/' %}
  <meta name="docsearch:version" content="lb2" />
{% endif %}
  • Contextual Search Boosting (docsearch initialization): Added logic to parse window.location.pathname to identify the user's current version, and passed that value into Algolia's searchParameters.
const path = window.location.pathname;
let currentVersion = 'lb4'; // Default version

if (path.includes('/lb3/')) {
    currentVersion = 'lb3';
} else if (path.includes('/lb2/')) {
    currentVersion = 'lb2';
}

// Inside the docsearch({}) config
searchParameters: {
    optionalFilters: [`version:${currentVersion}`]
}

Post-Merge Requirement

Action Required: Once this is merged and deployed, a manual re-crawl must be triggered in the Algolia Crawler Dashboard to index the new tags before the frontend optionalFilters will take effect.

Signed-off-by: Neeraj Deshmukh <neerajd002@gmail.com>
Copy link
Copy Markdown
Member

@dhmlau dhmlau left a comment

Choose a reason for hiding this comment

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

@neerajd002, thanks for taking a look at this problem! The changes look reasonable to me.

@dhmlau dhmlau merged commit 6e4edd7 into loopbackio:gh-pages Mar 3, 2026
2 checks passed
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.

Filter search results to show just LB4 content

2 participants