Skip to content

Make searching issues by keyword case insensitive on DB #14848

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

Conversation

zeripath
Copy link
Contributor

@zeripath zeripath commented Mar 2, 2021

Most DBs apart from SQLite will use a default Collation that is not case insensitive.
This means that SearchIssuesByKeyword becomes case sensitive for db indexing - in
contrast to the bleve and elastic indexers.

This PR simply uses UPPER(...) to do the LIKE - and although it may be more efficient
to change collations this would be a non-trivial task.

Fix #13663

Signed-off-by: Andrew Thornton [email protected]

Most DBs apart from SQLite will use a default Collation that is not case insensitive.
This means that SearchIssuesByKeyword becomes case sensitive for db indexing - in
contrast to the bleve and elastic indexers.

This PR simply uses UPPER(...) to do the LIKE - and although it may be more efficient
to change collations this would be a non-trivial task.

Fix go-gitea#13663

Signed-off-by: Andrew Thornton <[email protected]>
@zeripath
Copy link
Contributor Author

zeripath commented Mar 2, 2021

I've put in 1.14 but this could move if necessary.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 2, 2021
@zeripath zeripath added this to the 1.14.0 milestone Mar 2, 2021
@zeripath
Copy link
Contributor Author

zeripath commented Mar 2, 2021

This may be breaking - as it does change things but I think the previous behaviour is unintended

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 2, 2021
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 2, 2021
@6543 6543 merged commit def964e into go-gitea:master Mar 2, 2021
@zeripath zeripath deleted the fix-13663-db-issue-search-case-insensitive branch March 2, 2021 14:49
@lunny
Copy link
Member

lunny commented Mar 3, 2021

Another method is to implement a custom builder.Cond, we can name it ILike

// ILike defines ilike condition
type ILike [2]string
 
 var _ builder.Cond = ILike{"", ""}

// WriteTo write SQL to Writer
func (like ILike) WriteTo(w Writer) error {
   if _, err := fmt.Fprintf(w, "%s iLIKE ?", like[0]); err != nil {
   return err
}
// FIXME: if use other regular express, this will be failed. but for compatible, keep this
if like[1][0] == '%' \|\| like[1][len(like[1])-1] == '%' {
  w.Append(like[1])
} else {
  w.Append("%" + like[1] + "%")
}
  return nil
}

@6543
Copy link
Member

6543 commented Mar 3, 2021

@lunny sounds like a feature request/pull to xorm and follow up pull ...

@zeripath
Copy link
Contributor Author

zeripath commented Mar 3, 2021

ILIKE isn't present in sqlite, mysql or transact SQL.

Changing the collation for these columns is most likely to be the correct solution but a very fiddly one indeed.

@lunny
Copy link
Member

lunny commented Mar 3, 2021

@6543 The feature could added to xorm, but as an external Cond implementation, this will also work.

var likeFunc func(s, v string) builder.Cond
// if it's postgres {
    likeFunc = func(s, v string) builder.Cond {
        return ILike{s,v}
    }
} else {
    likeFunc = func(s, v string) builder.Cond {
        return builder.Like{s,v}
    }
}

Then replace all builder.Like{k,v} to likeFunc(k,v).

@ngugcx ngugcx mentioned this pull request Apr 22, 2021
6 tasks
@go-gitea go-gitea locked and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue search for part of a word, case sensitivity
5 participants