-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Rework suggestion backend #33538
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
Rework suggestion backend #33538
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ce2287f
Make index matched issues in the front of other keyword matched issues
lunny 684d744
Add logic if keyword is empty
lunny a2822a0
Add test and fix bug
lunny be910cc
Merge branch 'main' into lunny/fix_issue_suggestion
lunny f37f389
Remove prefix index search in suggestion feature
lunny 094df8c
Merge branch 'main' into lunny/fix_issue_suggestion
lunny e24690d
Follow @wxiaoguang's suggestion
lunny 8157fd6
Some improvements
lunny e952ac7
use case-insensitive like
wxiaoguang b68eda5
prefer latest updated issues
wxiaoguang e99ee8a
add comments
wxiaoguang fd0d877
Merge branch 'main' into lunny/fix_issue_suggestion
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 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 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 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,73 @@ | ||
// Copyright 2025 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package issue | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
|
||
issues_model "code.gitea.io/gitea/models/issues" | ||
repo_model "code.gitea.io/gitea/models/repo" | ||
"code.gitea.io/gitea/modules/optional" | ||
"code.gitea.io/gitea/modules/structs" | ||
) | ||
|
||
func GetSuggestion(ctx context.Context, repo *repo_model.Repository, isPull optional.Option[bool], keyword string) ([]*structs.Issue, error) { | ||
var issues issues_model.IssueList | ||
var err error | ||
pageSize := 5 | ||
if keyword == "" { | ||
issues, err = issues_model.FindLatestUpdatedIssues(ctx, repo.ID, isPull, pageSize) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} else { | ||
indexKeyword, _ := strconv.ParseInt(keyword, 10, 64) | ||
var issueByIndex *issues_model.Issue | ||
var excludedID int64 | ||
if indexKeyword > 0 { | ||
issueByIndex, err = issues_model.GetIssueByIndex(ctx, repo.ID, indexKeyword) | ||
if err != nil && !issues_model.IsErrIssueNotExist(err) { | ||
return nil, err | ||
} | ||
if issueByIndex != nil { | ||
excludedID = issueByIndex.ID | ||
pageSize-- | ||
} | ||
} | ||
|
||
issues, err = issues_model.FindIssuesSuggestionByKeyword(ctx, repo.ID, keyword, isPull, excludedID, pageSize) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if issueByIndex != nil { | ||
issues = append([]*issues_model.Issue{issueByIndex}, issues...) | ||
} | ||
} | ||
|
||
if err := issues.LoadPullRequests(ctx); err != nil { | ||
return nil, err | ||
} | ||
|
||
suggestions := make([]*structs.Issue, 0, len(issues)) | ||
for _, issue := range issues { | ||
suggestion := &structs.Issue{ | ||
ID: issue.ID, | ||
Index: issue.Index, | ||
Title: issue.Title, | ||
State: issue.State(), | ||
} | ||
|
||
if issue.IsPull && issue.PullRequest != nil { | ||
suggestion.PullRequest = &structs.PullRequestMeta{ | ||
HasMerged: issue.PullRequest.HasMerged, | ||
IsWorkInProgress: issue.PullRequest.IsWorkInProgress(ctx), | ||
} | ||
} | ||
suggestions = append(suggestions, suggestion) | ||
} | ||
|
||
return suggestions, nil | ||
} |
This file contains 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,57 @@ | ||
// Copyright 2025 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package issue | ||
|
||
import ( | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
repo_model "code.gitea.io/gitea/models/repo" | ||
"code.gitea.io/gitea/models/unittest" | ||
"code.gitea.io/gitea/modules/optional" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_Suggestion(t *testing.T) { | ||
assert.NoError(t, unittest.PrepareTestDatabase()) | ||
|
||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) | ||
|
||
testCases := []struct { | ||
keyword string | ||
isPull optional.Option[bool] | ||
expectedIndexes []int64 | ||
}{ | ||
{ | ||
keyword: "", | ||
expectedIndexes: []int64{5, 1, 4, 2, 3}, | ||
}, | ||
{ | ||
keyword: "1", | ||
expectedIndexes: []int64{1}, | ||
}, | ||
{ | ||
keyword: "issue", | ||
expectedIndexes: []int64{4, 1, 2, 3}, | ||
}, | ||
{ | ||
keyword: "pull", | ||
expectedIndexes: []int64{5}, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
t.Run(testCase.keyword, func(t *testing.T) { | ||
issues, err := GetSuggestion(db.DefaultContext, repo1, testCase.isPull, testCase.keyword) | ||
assert.NoError(t, err) | ||
|
||
issueIndexes := make([]int64, 0, len(issues)) | ||
for _, issue := range issues { | ||
issueIndexes = append(issueIndexes, issue.Index) | ||
} | ||
assert.EqualValues(t, testCase.expectedIndexes, issueIndexes) | ||
}) | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue_indexer.SearchIssues
does full-text search including issue content?I am not sure whether it is good enough to only search title(name) by this PR's new approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like github did what I did but with a updated order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Github will search both title and content but the title-matchted issue will be listed first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe GitHub uses search engine's ranking, not simply put something first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can merge this first. Searching content is not usable from my side.