Repository: go-gitea/gitea
File: models/issues/issue.go (Go)

Code before:
func FindIssuesTitleKeywords(ctx context.Context, repoID int64, keyword string, isPull optional.Option[bool], nonIDs []int64, pageSize int) (IssueList, error) {
	issues := make([]*Issue, 0, pageSize)
	sess := db.GetEngine(ctx).Where("repo_id = ?", repoID).
		And(isPullToCond(isPull))
	if len(nonIDs) > 0 {
		sess.NotIn("id", nonIDs)
	}
	err := sess.And("name LIKE ?", "%"+keyword+"%").
		OrderBy("created_unix DESC").
		Limit(pageSize).
		Find(&issues)
	return issues, err
}

func FindIssuesWithIndexPrefix(ctx context.Context, repoID, index int64, isPull optional.Option[bool], pageSize int) (IssueList, error) {
	var cond string
	switch {
	case setting.Database.Type.IsSQLite3():
		cond = "CAST(`index` AS TEXT) LIKE ?"
	case setting.Database.Type.IsMySQL():
		cond = "CAST(`index` AS CHAR) LIKE ?"
	case setting.Database.Type.IsPostgreSQL():
		cond = "index::TEXT LIKE ?"
	case setting.Database.Type.IsMSSQL():
		cond = "CAST([index] AS VARCHAR) LIKE ?"
	}

	issues := make([]*Issue, 0, pageSize)
	err := db.GetEngine(ctx).Where("repo_id = ?", repoID).
		And(isPullToCond(isPull)).
		Where(cond, fmt.Sprintf("%d%%", index)).
		OrderBy("`index` ASC").
		Limit(pageSize).
		Find(&issues)
	return issues, err
}

// GetIssueWithAttrsByIndex returns issue by index in a repository.
func GetIssueWithAttrsByIndex(ctx context.Context, repoID, index int64) (*Issue, error) {
	issue, err := GetIssueByIndex(ctx, repoID, index)
	if err != nil {
		return nil, err
	}
	return issue, issue.LoadAttributes(ctx)
}

// GetIssueByID returns an issue by given ID.
func GetIssueByID(ctx context.Context, id int64) (*Issue, error) {
	issue := new(Issue)
	has, err := db.GetEngine(ctx).ID(id).Get(issue)
	if err != nil {

Review comment (suggestion):
I do not think we should do so.

It should just query the issue full number, do not query the prefix (why a user would expect to use `#2` to list `#2354`? They only expects to see `#2` issue)

Code after:
func FindIssuesSuggestionByKeyword(ctx context.Context, repoID int64, keyword string, isPull optional.Option[bool], excludedID int64, pageSize int) (IssueList, error) {
	cond := builder.NewCond()
	if excludedID > 0 {
		cond = cond.And(builder.Neq{"`id`": excludedID})
	}

	// It seems that GitHub searches both title and content (maybe sorting by the search engine's ranking system?)
	// The first PR (https://github.com/go-gitea/gitea/pull/32327) uses "search indexer" to search "name(title) +  content"
	// But it seems that searching "content" (especially LIKE by DB engine) generates worse (unusable) results.
	// So now (https://github.com/go-gitea/gitea/pull/33538) it only searches "name(title)", leave the improvements to the future.
	cond = cond.And(db.BuildCaseInsensitiveLike("`name`", keyword))

	issues := make([]*Issue, 0, pageSize)
	err := db.GetEngine(ctx).Where("repo_id = ?", repoID).
		And(isPullToCond(isPull)).
		And(cond).
		OrderBy("updated_unix DESC, `index` DESC").
		Limit(pageSize).
		Find(&issues)
	return issues, err
}

// GetIssueWithAttrsByIndex returns issue by index in a repository.
func GetIssueWithAttrsByIndex(ctx context.Context, repoID, index int64) (*Issue, error) {
	issue, err := GetIssueByIndex(ctx, repoID, index)
	if err != nil {
		return nil, err
	}
	return issue, issue.LoadAttributes(ctx)
}

// GetIssueByID returns an issue by given ID.
func GetIssueByID(ctx context.Context, id int64) (*Issue, error) {
	issue := new(Issue)
	has, err := db.GetEngine(ctx).ID(id).Get(issue)
	if err != nil {
		return nil, err
	} else if !has {
		return nil, ErrIssueNotExist{id, 0, 0}
	}
	return issue, nil
}

// GetIssuesByIDs return issues with the given IDs.
// If keepOrder is true, the order of the returned issues will be the same as the given IDs.
func GetIssuesByIDs(ctx context.Context, issueIDs []int64, keepOrder ...bool) (IssueList, error) {
	issues := make([]*Issue, 0, len(issueIDs))

	if err := db.GetEngine(ctx).In("id", issueIDs).Find(&issues); err != nil {
		return nil, err
	}