[MM-5046] Fix emails search for Postgres DB (#21590)

* Support emails search in Postgres

* Add @ exception for postgres

* update comment

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Vishal
2022-11-22 22:32:33 +05:30
коммит произвёл GitHub
родитель 76f7872a50
Коммит c78b78ed5e
4 изменённых файлов: 49 добавлений и 39 удалений

Просмотреть файл

@@ -606,8 +606,7 @@ func (fs SqlFileInfoStore) Search(paramsList []*model.SearchParams, userId, team
terms := params.Terms
excludedTerms := params.ExcludedTerms
// these chars have special meaning and can be treated as spaces
for _, c := range specialSearchChar {
for _, c := range fs.specialSearchChars() {
terms = strings.Replace(terms, c, " ", -1)
excludedTerms = strings.Replace(excludedTerms, c, " ", -1)
}

Просмотреть файл

@@ -1788,18 +1788,6 @@ func (s *SqlPostStore) getParentsPostsPostgreSQL(channelId string, offset int, l
return posts, nil
}
var specialSearchChar = []string{
"<",
">",
"+",
"-",
"(",
")",
"~",
"@",
":",
}
// GetNthRecentPostTime returns the CreateAt time of the nth most recent post.
func (s *SqlPostStore) GetNthRecentPostTime(n int64) (int64, error) {
if n <= 0 {
@@ -1989,8 +1977,7 @@ func (s *SqlPostStore) search(teamId string, userId string, params *model.Search
}
}
// these chars have special meaning and can be treated as spaces
for _, c := range specialSearchChar {
for _, c := range s.specialSearchChars() {
terms = strings.Replace(terms, c, " ", -1)
excludedTerms = strings.Replace(excludedTerms, c, " ", -1)
}

Просмотреть файл

@@ -335,6 +335,28 @@ func (ss *SqlStore) DriverName() string {
return *ss.settings.DriverName
}
// specialSearchChars have special meaning and can be treated as spaces
func (ss *SqlStore) specialSearchChars() []string {
chars := []string{
"<",
">",
"+",
"-",
"(",
")",
"~",
":",
}
// Postgres can handle "@" without any errors
// Also helps postgres in enabling search for EmailAddresses
if ss.DriverName() != model.DatabaseDriverPostgres {
chars = append(chars, "@")
}
return chars
}
// computeBinaryParam returns whether the data source uses binary_parameters
// when using Postgres
func (ss *SqlStore) computeBinaryParam() (bool, error) {