Add archived repository filters to global code search#36968
Add archived repository filters to global code search#36968MaxWebZ wants to merge 5 commits intogo-gitea:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for filtering code search results by repository archived state, ensuring the archived flag is indexed and queryable across both Bleve and Elasticsearch, and updates UI + reindex behavior so results/facets remain consistent with the selected filter.
Changes:
- Index archived state in code index documents and add an archived filter to both Bleve and Elasticsearch search queries.
- Add an “Archived” filter dropdown to the shared code search UI and propagate the selection into language facet links.
- Reset code indexer status and trigger a full reindex when archiving/unarchiving repositories (web settings + API).
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| templates/shared/search/code/search.tmpl | Adds archived filter dropdown to the shared code search header UI. |
| templates/shared/search/code/results.tmpl | Preserves archived/search mode params in language facet links. |
| routers/web/repo/setting/setting.go | Resets code indexer status + queues reindex on archive/unarchive via web UI. |
| routers/web/explore/code.go | Parses archived filter and passes it into global code search options. |
| routers/api/v1/repo/repo.go | Resets code indexer status + queues reindex on archive/unarchive via API. |
| options/locale/locale_en-US.json | Adds i18n strings for the new code-search archived filter options. |
| modules/indexer/code/internal/indexer.go | Extends code indexer search options with an archived filter field. |
| modules/indexer/code/indexer_test.go | Adds test coverage for archived filtering and improves teardown cleanup. |
| modules/indexer/code/elasticsearch/elasticsearch.go | Adds archived field mapping, indexes it, bumps ES index version, and filters by it. |
| modules/indexer/code/bleve/bleve.go | Adds archived field mapping, indexes it, bumps Bleve index version, and filters by it. |
| models/repo/repo_indexer.go | Fixes indexer-status upsert logic to rely on row ID rather than empty commit SHA. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| <label class="item"><input type="radio" name="archived" {{if eq .ArchivedMode "include"}}checked{{end}} value="include"> {{ctx.Locale.Tr "search.code_archived_filter.all"}}</label> | ||
| <label class="item"><input type="radio" name="archived" {{if eq .ArchivedMode "exclude"}}checked{{end}} value="exclude"> {{ctx.Locale.Tr "search.code_archived_filter.not_archived"}}</label> | ||
| <label class="item"><input type="radio" name="archived" {{if .IsArchived.Value}}checked{{end}} value="only"> {{ctx.Locale.Tr "filter.is_archived"}}</label> |
There was a problem hiding this comment.
shared/search/code/search.tmpl is included by repo and user/org code search pages, but those handlers (e.g. routers/web/repo/search.go, routers/web/user/code.go) do not set .ArchivedMode / .IsArchived. Using eq .ArchivedMode ... and .IsArchived.Value will cause template execution errors (nil/incompatible types) on those pages, and even if it doesn’t error, the archived radio state/filter won’t work there.
Consider initializing these values for all code-search pages (e.g. in common.PrepareCodeSearch), and ensure the user/org code search handler passes the parsed archived filter into code_indexer.PerformSearch. For repo-scoped search, it may be better to hide the archived filter entirely since the repo is already fixed.
| <label class="item"><input type="radio" name="archived" {{if eq .ArchivedMode "include"}}checked{{end}} value="include"> {{ctx.Locale.Tr "search.code_archived_filter.all"}}</label> | |
| <label class="item"><input type="radio" name="archived" {{if eq .ArchivedMode "exclude"}}checked{{end}} value="exclude"> {{ctx.Locale.Tr "search.code_archived_filter.not_archived"}}</label> | |
| <label class="item"><input type="radio" name="archived" {{if .IsArchived.Value}}checked{{end}} value="only"> {{ctx.Locale.Tr "filter.is_archived"}}</label> | |
| {{if .ArchivedMode}} | |
| <label class="item"><input type="radio" name="archived" {{if eq .ArchivedMode "include"}}checked{{end}} value="include"> {{ctx.Locale.Tr "search.code_archived_filter.all"}}</label> | |
| <label class="item"><input type="radio" name="archived" {{if eq .ArchivedMode "exclude"}}checked{{end}} value="exclude"> {{ctx.Locale.Tr "search.code_archived_filter.not_archived"}}</label> | |
| <label class="item"><input type="radio" name="archived" {{if eq .ArchivedMode "only"}}checked{{end}} value="only"> {{ctx.Locale.Tr "filter.is_archived"}}</label> | |
| {{end}} |
There was a problem hiding this comment.
Fixed in the latest commit
|
One UI suggestion: Render in the dropdown this: [x] Archived It would be similar UX than the label filter in issue list, could either be actual checkboxes or just SVG checkmark like in the label filter. In the future, this could be extended to add more checkbox groups separated by a horizontal separator. |
I agree, that would be closer to the existing Gitea UI patterns. |
|
The original issue and related PR's participants (jpraet, lunny, silverwind, lafriks, delvh) are maintainers, they should know more details than me. |
| if err := actions_service.CleanRepoScheduleTasks(ctx, repo); err != nil { | ||
| log.Error("CleanRepoScheduleTasks for archived repo %s/%s: %v", ctx.Repo.Owner.Name, repo.Name, err) | ||
| } | ||
| if setting.Indexer.RepoIndexerEnabled { |
There was a problem hiding this comment.
It's better to have a new notifier event like ArchiveRepository.
| case archivedModeInclude: | ||
| return archivedModeInclude, optional.None[bool]() | ||
| case "": | ||
| return archivedModeInclude, optional.None[bool]() |
There was a problem hiding this comment.
| case archivedModeInclude: | |
| return archivedModeInclude, optional.None[bool]() | |
| case "": | |
| return archivedModeInclude, optional.None[bool]() |

The repository archived state is now indexed for code search and used in both supported search backends, so result counts, pagination, sorting, and language facets stay consistent with the selected filter.
A filter dropdown similar to the one on the repositories page has been added to the code search page.
Archiving or unarchiving a repository now also resets the code index status so the repository is fully reindexed and the archived state is reflected in search results.
UI Before:

UI after:

Fixes #17824.