Skip to content

Fix search index not trimming numerical ordering prefixes#2408

Merged
emmadesilva merged 1 commit intomasterfrom
fix-search-index-not-trimming-numerical-ordering-prefixes
Apr 3, 2026
Merged

Fix search index not trimming numerical ordering prefixes#2408
emmadesilva merged 1 commit intomasterfrom
fix-search-index-not-trimming-numerical-ordering-prefixes

Conversation

@emmadesilva
Copy link
Copy Markdown
Member

🐛 Fix search index not trimming numeric ordering prefixes

Summary

This PR fixes an issue where documentation search results generated incorrect URLs when source files used numeric ordering prefixes (e.g. 01-, 02-).

Hyde correctly strips these prefixes when generating the final documentation pages, but the search index was still using the original filename, causing broken links (404s) when users clicked search results.


✅ What’s fixed

  • Search index now uses the page routeKey instead of the raw file identifier

  • Numeric prefixes like 01- and 02- are properly removed from:

    • slug
    • destination (URL)
  • Nested documentation structures are handled correctly

  • Fallback title generation no longer includes numeric prefixes


🔍 Example

Before

Source file:

_docs/01-category/02-item-name.md

Generated page:

/docs/item-name.html

Search result (incorrect):

/docs/02-item-name.html ❌ (404)

After

Search result:

/docs/item-name.html ✅

💡 Implementation details

  • Updated search index generation to use basename($page->routeKey) instead of $page->identifier
  • Introduced getCleanBasename() in HydePageDataFactory to strip numeric prefixes when generating fallback titles
  • Reused NumericalPageOrderingHelper to ensure consistent prefix handling across the framework
  • Applied the same cleanup logic to parent directory names for index pages

🧪 Tests

Added tests to ensure:

  • Numeric prefixes are stripped from search results
  • Nested directories with numeric prefixes are handled correctly
  • Search index does not contain any ordering prefixes

🎯 Why this approach

Instead of duplicating filename-cleaning logic in the search index, this PR aligns search behavior with Hyde’s routing system by using routeKey as the source of truth.

This ensures:

  • Consistency between generated pages and search results
  • Reduced risk of future mismatches
  • Cleaner and more maintainable code

🔗 Fixes

Fixes hydephp/hyde#324

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7fcae80) to head (721c534).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##              master     #2408   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity      2000      2003    +3     
===========================================
  Files            197       197           
  Lines           5127      5135    +8     
===========================================
+ Hits            5127      5135    +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@emmadesilva emmadesilva force-pushed the fix-search-index-not-trimming-numerical-ordering-prefixes branch from a195b86 to 721c534 Compare April 3, 2026 18:22
@emmadesilva emmadesilva merged commit 95cee50 into master Apr 3, 2026
20 of 21 checks passed
@emmadesilva emmadesilva deleted the fix-search-index-not-trimming-numerical-ordering-prefixes branch April 3, 2026 18:25
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.

Search results generate incorrect URLs when docs filenames use numeric ordering prefixes

1 participant