-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Allow code search by filename #32210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0de61a1
Allow code search by filename
bsofiato 7791971
Included documentation about fuzziness' semantics within Bleve
bsofiato 37dc769
Adding repo structure to description
bsofiato 765e2f4
Included some descriptions for the code search test scenarios
bsofiato 69492da
Merge branch 'main' into feature/search_by_path
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1517,3 +1517,40 @@ | |
repo_admin_change_team_access: false | ||
theme: "" | ||
keep_activity_private: false | ||
|
||
- | ||
id: 42 | ||
lower_name: org42 | ||
name: org42 | ||
full_name: Org42 | ||
email: [email protected] | ||
keep_email_private: false | ||
email_notifications_preference: onmention | ||
passwd: ZogKvWdyEx:password | ||
passwd_hash_algo: dummy | ||
must_change_password: false | ||
login_source: 0 | ||
login_name: org42 | ||
type: 1 | ||
salt: ZogKvWdyEx | ||
max_repo_creation: -1 | ||
is_active: false | ||
is_admin: false | ||
is_restricted: false | ||
allow_git_hook: false | ||
allow_import_local: false | ||
allow_create_organization: true | ||
prohibit_login: false | ||
avatar: avatar42 | ||
avatar_email: [email protected] | ||
use_custom_avatar: false | ||
num_followers: 0 | ||
num_following: 0 | ||
num_stars: 0 | ||
num_repos: 1 | ||
num_teams: 0 | ||
num_members: 0 | ||
visibility: 0 | ||
repo_admin_change_team_access: false | ||
theme: "" | ||
keep_activity_private: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package path | ||
|
||
import ( | ||
"slices" | ||
"strings" | ||
|
||
"github.com/blevesearch/bleve/v2/analysis" | ||
"github.com/blevesearch/bleve/v2/registry" | ||
) | ||
|
||
const ( | ||
Name = "gitea/path" | ||
) | ||
|
||
type TokenFilter struct{} | ||
|
||
func NewTokenFilter() *TokenFilter { | ||
return &TokenFilter{} | ||
} | ||
|
||
func TokenFilterConstructor(config map[string]any, cache *registry.Cache) (analysis.TokenFilter, error) { | ||
return NewTokenFilter(), nil | ||
} | ||
|
||
func (s *TokenFilter) Filter(input analysis.TokenStream) analysis.TokenStream { | ||
if len(input) == 1 { | ||
// if there is only one token, we dont need to generate the reversed chain | ||
return generatePathTokens(input, false) | ||
} | ||
|
||
normal := generatePathTokens(input, false) | ||
reversed := generatePathTokens(input, true) | ||
|
||
return append(normal, reversed...) | ||
} | ||
|
||
// Generates path tokens from the input tokens. | ||
// This mimics the behavior of the path hierarchy tokenizer in ES. It takes the input tokens and combine them, generating a term for each component | ||
// in tree (e.g., foo/bar/baz.md will generate foo, foo/bar, and foo/bar/baz.md). | ||
// | ||
// If the reverse flag is set, the order of the tokens is reversed (the same input will generate baz.md, baz.md/bar, baz.md/bar/foo). This is useful | ||
// to efficiently search for filenames without supplying the fullpath. | ||
func generatePathTokens(input analysis.TokenStream, reversed bool) analysis.TokenStream { | ||
delvh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
terms := make([]string, 0, len(input)) | ||
longestTerm := 0 | ||
|
||
if reversed { | ||
slices.Reverse(input) | ||
} | ||
|
||
for i := 0; i < len(input); i++ { | ||
var sb strings.Builder | ||
sb.WriteString(string(input[0].Term)) | ||
|
||
for j := 1; j < i; j++ { | ||
sb.WriteString("/") | ||
sb.WriteString(string(input[j].Term)) | ||
} | ||
|
||
term := sb.String() | ||
|
||
if longestTerm < len(term) { | ||
longestTerm = len(term) | ||
} | ||
|
||
terms = append(terms, term) | ||
} | ||
|
||
output := make(analysis.TokenStream, 0, len(terms)) | ||
|
||
for _, term := range terms { | ||
var start, end int | ||
|
||
if reversed { | ||
start = 0 | ||
end = len(term) | ||
} else { | ||
start = longestTerm - len(term) | ||
end = longestTerm | ||
} | ||
|
||
token := analysis.Token{ | ||
Position: 1, | ||
Start: start, | ||
End: end, | ||
Type: analysis.AlphaNumeric, | ||
Term: []byte(term), | ||
} | ||
|
||
output = append(output, &token) | ||
} | ||
|
||
return output | ||
} | ||
|
||
func init() { | ||
registry.RegisterTokenFilter(Name, TokenFilterConstructor) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.