@@ -17,6 +17,7 @@ import (
1717 user_model "code.gitea.io/gitea/models/user"
1818 "code.gitea.io/gitea/modules/container"
1919 "code.gitea.io/gitea/modules/log"
20+ "code.gitea.io/gitea/modules/optional"
2021 "code.gitea.io/gitea/modules/setting"
2122 api "code.gitea.io/gitea/modules/structs"
2223 "code.gitea.io/gitea/modules/timeutil"
@@ -531,6 +532,45 @@ func GetIssueByIndex(ctx context.Context, repoID, index int64) (*Issue, error) {
531532 return issue , nil
532533}
533534
535+ func isPullToCond (isPull optional.Option [bool ]) builder.Cond {
536+ if isPull .Has () {
537+ return builder.Eq {"is_pull" : isPull .Value ()}
538+ }
539+ return builder .NewCond ()
540+ }
541+
542+ func FindLatestUpdatedIssues (ctx context.Context , repoID int64 , isPull optional.Option [bool ], pageSize int ) (IssueList , error ) {
543+ issues := make ([]* Issue , 0 , pageSize )
544+ err := db .GetEngine (ctx ).Where ("repo_id = ?" , repoID ).
545+ And (isPullToCond (isPull )).
546+ OrderBy ("updated_unix DESC" ).
547+ Limit (pageSize ).
548+ Find (& issues )
549+ return issues , err
550+ }
551+
552+ func FindIssuesSuggestionByKeyword (ctx context.Context , repoID int64 , keyword string , isPull optional.Option [bool ], excludedID int64 , pageSize int ) (IssueList , error ) {
553+ cond := builder .NewCond ()
554+ if excludedID > 0 {
555+ cond = cond .And (builder.Neq {"`id`" : excludedID })
556+ }
557+
558+ // It seems that GitHub searches both title and content (maybe sorting by the search engine's ranking system?)
559+ // The first PR (https://github.com/go-gitea/gitea/pull/32327) uses "search indexer" to search "name(title) + content"
560+ // But it seems that searching "content" (especially LIKE by DB engine) generates worse (unusable) results.
561+ // So now (https://github.com/go-gitea/gitea/pull/33538) it only searches "name(title)", leave the improvements to the future.
562+ cond = cond .And (db .BuildCaseInsensitiveLike ("`name`" , keyword ))
563+
564+ issues := make ([]* Issue , 0 , pageSize )
565+ err := db .GetEngine (ctx ).Where ("repo_id = ?" , repoID ).
566+ And (isPullToCond (isPull )).
567+ And (cond ).
568+ OrderBy ("updated_unix DESC, `index` DESC" ).
569+ Limit (pageSize ).
570+ Find (& issues )
571+ return issues , err
572+ }
573+
534574// GetIssueWithAttrsByIndex returns issue by index in a repository.
535575func GetIssueWithAttrsByIndex (ctx context.Context , repoID , index int64 ) (* Issue , error ) {
536576 issue , err := GetIssueByIndex (ctx , repoID , index )
0 commit comments