Skip to content

x/pkgsite: support offline search in local module cache #79620

Description

@ali-hasehmi

What is the problem?
When running the pkgsite server locally in offline mode using the module cache (e.g., pkgsite -cache), users can view documentation for cached modules if they know and enter the exact URL. However, the search functionality currently does not work for cached modules. The local FetchDataSource defaults to internal.NoSearch because modCacheModuleGetter does not implement the SearchableModuleGetter interface.

This creates friction for offline development, as users must memorize exact module paths instead of being able to search their local cache.

What is the proposed solution?
Implement the Search method on modCacheModuleGetter in internal/fetch/getters.go so that the local FetchDataSource can route search queries to the local module cache.

To keep the search fast and responsive without requiring a persistent database or heavy AST parsing on the fly, the implementation can perform a shallow search:

  1. Scan the GOMODCACHE/cache/download directory structure.
  2. Identify valid cached modules by looking for @v directories that contain a .zip file (this filters out "ghost" modules where the go toolchain only downloaded the .mod and .info files for graph resolution).
  3. Extract the module path using module.UnescapePath and score it using pkgsite's existing fuzzy.NewSymbolMatcher.
  4. Return the matching module roots as internal.SearchResults.

Next Steps
I have a working local implementation of this fast/shallow search approach and am currently running the tests via ./all.bash. I will submit a Gerrit CL shortly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions