- 
 
 - 
  Notifications
 
You must be signed in to change notification settings  - Fork 6.2k
 
feat(search): support code search by zoekt #33850
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
 
  Open
 
 
 adlternative
 wants to merge
 1
 commit into
 go-gitea:main 
 
 
  
from
adlternative:adl/dev/search/support-zoekt-code-indexer 
 
 
 
  
 
 
 
 
 
 
 
 
 
 
 
 +779
 
 
 −5
 
 
 
 
 
 
 
 
  Open
 Changes from all commits
 Commits
 
 
 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
 
 
 
 30 changes: 30 additions & 0 deletions
 
 
 
 assets/go-licenses.json
 
 
 
 
  
 
 
 
 
 
 Oops, something went wrong.
 
 
 
 
 
 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
 
 
 
 
 
 
 
 
 95 changes: 95 additions & 0 deletions
 
 
 
 go.sum
 
 
 
 
  
 
 
 
 
 
 Oops, something went wrong.
 
 
 
 
 
 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 | 
|---|---|---|
| 
 
 
 
  | 
 @@ -39,6 +39,10 @@ func getRepoChanges(ctx context.Context, repo *repo_model.Repository, revision s | |
| needGenesis = len(stdout) == 0 | ||
| } | ||
| 
  | 
||
| // TODO: check if zoekt index file meta status is not sync with db index status, if not, get genesis changes | ||
| 
  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we still need this comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this check can help ensure the correctness of the index data, but it's not necessary at the moment—it can be added in the future.  | 
||
| //if setting.Indexer.RepoType == "zoekt" { | ||
| //} | ||
| 
  | 
||
| if needGenesis { | ||
| return genesisChanges(ctx, repo, revision) | ||
| } | ||
| 
 
 
 
  | 
 
 ||
 
 
 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
 
 
 
 
 
 
 
 
 49 changes: 49 additions & 0 deletions
 
 
 
 modules/indexer/code/zoekt/utils.go
 
 
 
 
  
 
 
 
 
 
 
 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,49 @@ | ||
| // Copyright 2025 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
| 
  | 
||
| package zoekt | ||
| 
  | 
||
| import "unicode/utf8" | ||
| 
  | 
||
| // Bitmap used by func special to check whether a character needs to be escaped. | ||
| var specialBytes [16]byte | ||
| 
  | 
||
| // special reports whether byte b needs to be escaped by QuoteMeta. | ||
| func special(b byte) bool { | ||
| return b < utf8.RuneSelf && specialBytes[b%16]&(1<<(b/16)) != 0 | ||
| } | ||
| 
  | 
||
| func init() { | ||
| for _, b := range []byte(`-:\.+*?()|[]{}^$`) { | ||
| specialBytes[b%16] |= 1 << (b / 16) | ||
| } | ||
| } | ||
| 
  | 
||
| func QuoteMeta(s string) string { | ||
| // A byte loop is correct because all metacharacters are ASCII. | ||
| var i int | ||
| for i = 0; i < len(s); i++ { | ||
| if special(s[i]) { | ||
| break | ||
| } | ||
| } | ||
| // No meta characters found, so return original string. | ||
| if i >= len(s) { | ||
| return s | ||
| } | ||
| 
  | 
||
| b := make([]byte, 3*len(s)-2*i) | ||
| copy(b, s[:i]) | ||
| j := i | ||
| for ; i < len(s); i++ { | ||
| if special(s[i]) { | ||
| b[j] = '\\' | ||
| j++ | ||
| b[j] = '\\' | ||
| j++ | ||
| } | ||
| b[j] = s[i] | ||
| j++ | ||
| } | ||
| return string(b[:j]) | ||
| } | 
 
 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.