@@ -10,6 +10,7 @@ import (
1010 "html/template"
1111 "regexp"
1212 "slices"
13+ "strconv"
1314
1415 "code.gitea.io/gitea/models/db"
1516 project_model "code.gitea.io/gitea/models/project"
@@ -519,38 +520,19 @@ func FindLatestIssues(ctx context.Context, repoID int64, isPull optional.Option[
519520 return issues , err
520521}
521522
522- func FindIssuesTitleKeywords (ctx context.Context , repoID int64 , keyword string , isPull optional.Option [bool ], nonIDs []int64 , pageSize int ) (IssueList , error ) {
523- issues := make ([]* Issue , 0 , pageSize )
524- sess := db .GetEngine (ctx ).Where ("repo_id = ?" , repoID ).
525- And (isPullToCond (isPull ))
526- if len (nonIDs ) > 0 {
527- sess .NotIn ("id" , nonIDs )
528- }
529- err := sess .And ("name LIKE ?" , "%" + keyword + "%" ).
530- OrderBy ("created_unix DESC" ).
531- Limit (pageSize ).
532- Find (& issues )
533- return issues , err
534- }
535-
536- func FindIssuesWithIndexPrefix (ctx context.Context , repoID , index int64 , isPull optional.Option [bool ], pageSize int ) (IssueList , error ) {
537- var cond string
538- switch {
539- case setting .Database .Type .IsSQLite3 ():
540- cond = "CAST(`index` AS TEXT) LIKE ?"
541- case setting .Database .Type .IsMySQL ():
542- cond = "CAST(`index` AS CHAR) LIKE ?"
543- case setting .Database .Type .IsPostgreSQL ():
544- cond = "index::TEXT LIKE ?"
545- case setting .Database .Type .IsMSSQL ():
546- cond = "CAST([index] AS VARCHAR) LIKE ?"
523+ func FindIssuesSuggestionByKeyword (ctx context.Context , repoID int64 , keyword string , isPull optional.Option [bool ], pageSize int ) (IssueList , error ) {
524+ indexKeyword , _ := strconv .ParseInt (keyword , 10 , 64 )
525+ cond := builder .NewCond ()
526+ if indexKeyword > 0 {
527+ cond = cond .Or (builder.Eq {"`index`" : indexKeyword })
547528 }
529+ cond = cond .Or (builder .Expr ("name LIKE ?" , "%" + keyword + "%" ))
548530
549531 issues := make ([]* Issue , 0 , pageSize )
550532 err := db .GetEngine (ctx ).Where ("repo_id = ?" , repoID ).
551533 And (isPullToCond (isPull )).
552- Where (cond , fmt . Sprintf ( "%d%%" , index ) ).
553- OrderBy ("`index` ASC " ).
534+ And (cond ).
535+ OrderBy ("`index` DESC " ).
554536 Limit (pageSize ).
555537 Find (& issues )
556538 return issues , err
0 commit comments