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:
- Scan the
GOMODCACHE/cache/download directory structure.
- 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).
- Extract the module path using
module.UnescapePath and score it using pkgsite's existing fuzzy.NewSymbolMatcher.
- 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.
What is the problem?
When running the
pkgsiteserver 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 localFetchDataSourcedefaults tointernal.NoSearchbecausemodCacheModuleGetterdoes not implement theSearchableModuleGetterinterface.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
Searchmethod onmodCacheModuleGetterininternal/fetch/getters.goso that the localFetchDataSourcecan 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:
GOMODCACHE/cache/downloaddirectory structure.@vdirectories that contain a.zipfile (this filters out "ghost" modules where thegotoolchain only downloaded the.modand.infofiles for graph resolution).module.UnescapePathand score it usingpkgsite's existingfuzzy.NewSymbolMatcher.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.