mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-19 15:14:40 +09:00
Adds GitHub-style code search endpoints and makes code search behave the
same in the web UI and the API, whether it runs on git grep, bleve or
Elasticsearch.
- `GET /repos/{owner}/{repo}/code/search` searches any branch, tag or
commit with git grep, so it works without the code indexer.
- `GET /search/code` searches the default branches of all accessible
repositories with the code indexer.
- One query syntax everywhere: every term must match a file's content or
path, case-insensitively. It supports `"phrases"`, `/regexp/` (git grep
only) and the `path:`, `language:`, `repo:`, `user:` and `org:`
qualifiers. Invalid queries return an error.
- All engines apply the same include, exclude, vendored and size rules,
and return every match. The web UI shows them as multiple snippets per
file with the matched text highlighted.
<img width="359" height="295" alt="image"
src="https://github.com/user-attachments/assets/59b7aa66-b1dc-4938-9ef9-66668ae08d7c"
/>
Fixes: https://github.com/go-gitea/gitea/issues/10706
Fixed: https://github.com/go-gitea/gitea/issues/15841
Fixes: https://github.com/go-gitea/gitea/issues/31375
Related: https://gitea.com/gitea/gitea-mcp/issues/280
Docs: https://gitea.com/gitea/docs/pulls/615
AI usage disclosure: Yes, I used AI to write code, review changes and
verify the factuality of the overview I provided. I take full
responsibility for the code in this PR.
---------
Co-authored-by: silverwind <me@silverwind.io>
41 lines
1.2 KiB
Handlebars
41 lines
1.2 KiB
Handlebars
<form class="ui form ignore-dirty">
|
|
{{template "shared/search/combo" (dict
|
|
"Disabled" .CodeIndexerUnavailable
|
|
"Value" .Keyword
|
|
"Placeholder" (ctx.Locale.Tr "search.code_kind")
|
|
)}}
|
|
</form>
|
|
<div class="divider"></div>
|
|
<div class="ui list">
|
|
{{template "base/alert" .}}
|
|
{{if .CodeSearchError}}
|
|
<div class="ui error message">
|
|
<p>{{ctx.Locale.Tr "search.code_search_invalid" .CodeSearchError}}</p>
|
|
</div>
|
|
{{else if .CodeIndexerUnavailable}}
|
|
<div class="ui error message">
|
|
<p>{{ctx.Locale.Tr "search.code_search_unavailable"}}</p>
|
|
</div>
|
|
{{else}}
|
|
{{if not .IsRepoIndexerEnabled}}
|
|
<div class="ui message">
|
|
<p>{{ctx.Locale.Tr "search.code_search_by_git_grep"}}</p>
|
|
</div>
|
|
{{end}}
|
|
{{if .CodeSearchIncomplete}}
|
|
<div class="ui warning message">{{ctx.Locale.Tr "search.code_search_incomplete"}}</div>
|
|
{{end}}
|
|
{{if .SearchResults}}
|
|
{{template "shared/search/code/results" .}}
|
|
{{else if .Keyword}}
|
|
<div>{{ctx.Locale.Tr "search.no_results"}}</div>
|
|
{{else}}
|
|
<div class="empty-placeholder">
|
|
{{svg "octicon-search" 48}}
|
|
<h2>{{ctx.Locale.Tr "search.code_empty"}}</h2>
|
|
<p>{{ctx.Locale.Tr "search.code_empty_description"}}</p>
|
|
</div>
|
|
{{end}}
|
|
{{end}}
|
|
</div>
|