@@ -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"
@@ -501,6 +502,45 @@ func GetIssueByIndex(ctx context.Context, repoID, index int64) (*Issue, error) {
501502 return issue , nil
502503}
503504
505+ func isPullToCond (isPull optional.Option [bool ]) builder.Cond {
506+ if isPull .Has () {
507+ return builder.Eq {"is_pull" : isPull .Value ()}
508+ }
509+ return builder .NewCond ()
510+ }
511+
512+ func FindLatestUpdatedIssues (ctx context.Context , repoID int64 , isPull optional.Option [bool ], pageSize int ) (IssueList , error ) {
513+ issues := make ([]* Issue , 0 , pageSize )
514+ err := db .GetEngine (ctx ).Where ("repo_id = ?" , repoID ).
515+ And (isPullToCond (isPull )).
516+ OrderBy ("updated_unix DESC" ).
517+ Limit (pageSize ).
518+ Find (& issues )
519+ return issues , err
520+ }
521+
522+ func FindIssuesSuggestionByKeyword (ctx context.Context , repoID int64 , keyword string , isPull optional.Option [bool ], excludedID int64 , pageSize int ) (IssueList , error ) {
523+ cond := builder .NewCond ()
524+ if excludedID > 0 {
525+ cond = cond .And (builder.Neq {"`id`" : excludedID })
526+ }
527+
528+ // It seems that GitHub searches both title and content (maybe sorting by the search engine's ranking system?)
529+ // The first PR (https://github.com/go-gitea/gitea/pull/32327) uses "search indexer" to search "name(title) + content"
530+ // But it seems that searching "content" (especially LIKE by DB engine) generates worse (unusable) results.
531+ // So now (https://github.com/go-gitea/gitea/pull/33538) it only searches "name(title)", leave the improvements to the future.
532+ cond = cond .And (db .BuildCaseInsensitiveLike ("`name`" , keyword ))
533+
534+ issues := make ([]* Issue , 0 , pageSize )
535+ err := db .GetEngine (ctx ).Where ("repo_id = ?" , repoID ).
536+ And (isPullToCond (isPull )).
537+ And (cond ).
538+ OrderBy ("updated_unix DESC, `index` DESC" ).
539+ Limit (pageSize ).
540+ Find (& issues )
541+ return issues , err
542+ }
543+
504544// GetIssueWithAttrsByIndex returns issue by index in a repository.
505545func GetIssueWithAttrsByIndex (ctx context.Context , repoID , index int64 ) (* Issue , error ) {
506546 issue , err := GetIssueByIndex (ctx , repoID , index )
0 commit comments