You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gitea/models
Bruno Sofiato 900ac62251
Allow code search by filename (#32210)
This is a large and complex PR, so let me explain in detail its changes.

First, I had to create new index mappings for Bleve and ElasticSerach as
the current ones do not support search by filename. This requires Gitea
to recreate the code search indexes (I do not know if this is a breaking
change, but I feel it deserves a heads-up).

I've used [this
approach](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/analysis-pathhierarchy-tokenizer.html)
to model the filename index. It allows us to efficiently search for both
the full path and the name of a file. Bleve, however, does not support
this out-of-box, so I had to code a brand new [token
filter](https://blevesearch.com/docs/Token-Filters/) to generate the
search terms.

I also did an overhaul in the `indexer_test.go` file. It now asserts the
order of the expected results (this is important since matches based on
the name of a file are more relevant than those based on its content).
I've added new test scenarios that deal with searching by filename. They
use a new repo included in the Gitea fixture.

The screenshot below depicts how Gitea shows the search results. It
shows results based on content in the same way as the current version
does. In matches based on the filename, the first seven lines of the
file contents are shown (BTW, this is how GitHub does it).


![image](https://github.com/user-attachments/assets/9d938d86-1a8d-4f89-8644-1921a473e858)

Resolves #32096

---------

Signed-off-by: Bruno Sofiato <bruno.sofiato@gmail.com>
4 months ago
..
actions Show latest run when visit /run/latest (#31808) 6 months ago
activities Don't join repository when loading action table data (#32127) 4 months ago
admin Fix javascript error when an anonymous user visiting migration page (#32144) 4 months ago
asymkey bump to go 1.23 (#31855) 5 months ago
auth Fix nuget/conan/container packages upload bugs (#31967) 5 months ago
avatars Replace 10 more gt- classes with tw- (#29945) 11 months ago
db bump to go 1.23 (#31855) 5 months ago
dbfs Enable `unparam` linter (#31277) 8 months ago
fixtures Allow code search by filename (#32210) 4 months ago
git Show lock owner instead of repo owner on LFS setting page (#31788) 6 months ago
issues Allow filtering PRs by poster in the ListPullRequests API (#32209) 4 months ago
migrations Support repo license (#24872) 4 months ago
organization Add option to filter board cards by labels and assignees (#31999) 5 months ago
packages Fix package list performance (#30520) 10 months ago
perm Clarify permission "HasAccess" behavior (#30585) 10 months ago
project Fixes for unreachable project issues when transfer repository from organization (#31770) 6 months ago
pull Add support for sha256 repositories (#23894) 1 year ago
repo Allow code search by filename (#32210) 4 months ago
secret Clarify Actions resources ownership (#31724) 6 months ago
shared/types Refactor locale&string&template related code (#29165) 12 months ago
system Refactor deletion (#28610) 1 year ago
unit Refactor repo unit "disabled" check (#31389) 8 months ago
unittest Add some tests to clarify the "must-change-password" behavior (#30693) 9 months ago
user Allow code search by filename (#32210) 4 months ago
webhook Store webhook event in database (#29145) 11 months ago
error.go Add merge style `fast-forward-only` (#28954) 12 months ago
fixture_generation.go Replace more db.DefaultContext (#27628) 1 year ago
fixture_test.go Replace more db.DefaultContext (#27628) 1 year ago
main_test.go make writing main test easier (#27270) 1 year ago
org.go Add user blocking (#29028) 11 months ago
org_team.go Clarify permission "HasAccess" behavior (#30585) 10 months ago
org_team_test.go Add user blocking (#29028) 11 months ago
org_test.go Add user blocking (#29028) 11 months ago
repo.go Refactor deletion (#28610) 1 year ago
repo_test.go Penultimate round of `db.DefaultContext` refactor (#27414) 1 year ago
repo_transfer.go chore: use errors.New to replace fmt.Errorf with no parameters will much better (#30621) 9 months ago