Skip to content

Add archived repository filters to global code search#36968

Open
MaxWebZ wants to merge 5 commits intogo-gitea:mainfrom
MaxWebZ:main
Open

Add archived repository filters to global code search#36968
MaxWebZ wants to merge 5 commits intogo-gitea:mainfrom
MaxWebZ:main

Conversation

@MaxWebZ
Copy link
Copy Markdown
Contributor

@MaxWebZ MaxWebZ commented Mar 23, 2026

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:
image

UI after:
image

Fixes #17824.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 23, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +17 to +19
<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>
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
<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}}

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in the latest commit

Comment thread templates/shared/search/code/results.tmpl
@silverwind
Copy link
Copy Markdown
Member

silverwind commented Mar 25, 2026

One UI suggestion: Render in the dropdown this:

[x] Archived
[x] Not 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.

@MaxWebZ
Copy link
Copy Markdown
Contributor Author

MaxWebZ commented Mar 26, 2026

One UI suggestion: Render in the dropdown this:

[x] Archived [x] Not 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.
Done.

@MaxWebZ MaxWebZ requested a review from wxiaoguang April 5, 2026 12:36
@wxiaoguang wxiaoguang removed their request for review April 5, 2026 12:41
@wxiaoguang
Copy link
Copy Markdown
Contributor

wxiaoguang commented Apr 5, 2026

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 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's better to have a new notifier event like ArchiveRepository.

Comment on lines +31 to +34
case archivedModeInclude:
return archivedModeInclude, optional.None[bool]()
case "":
return archivedModeInclude, optional.None[bool]()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
case archivedModeInclude:
return archivedModeInclude, optional.None[bool]()
case "":
return archivedModeInclude, optional.None[bool]()

@lunny
Copy link
Copy Markdown
Member

lunny commented Apr 5, 2026

image Unarchived filter doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to exclude archived repo's from code search results

6 participants