PLT-4935 Fix searching for full email (#4947)
* Fix searching for full email * Fix unit test
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
3ae8e9789e
Коммит
3df8f33437
@@ -1291,15 +1291,35 @@ var specialUserSearchChar = []string{
|
|||||||
"(",
|
"(",
|
||||||
")",
|
")",
|
||||||
"~",
|
"~",
|
||||||
"@",
|
|
||||||
":",
|
":",
|
||||||
"*",
|
"*",
|
||||||
"\"",
|
"\"",
|
||||||
|
"!",
|
||||||
|
"@",
|
||||||
|
}
|
||||||
|
|
||||||
|
var postgresSearchChar = []string{
|
||||||
|
"(",
|
||||||
|
")",
|
||||||
|
":",
|
||||||
|
"!",
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us SqlUserStore) performSearch(searchQuery string, term string, options map[string]bool, parameters map[string]interface{}) StoreResult {
|
func (us SqlUserStore) performSearch(searchQuery string, term string, options map[string]bool, parameters map[string]interface{}) StoreResult {
|
||||||
result := StoreResult{}
|
result := StoreResult{}
|
||||||
|
|
||||||
|
// Special handling for emails
|
||||||
|
originalTerm := term
|
||||||
|
postgresUseOriginalTerm := false
|
||||||
|
if strings.Contains(term, "@") && strings.Contains(term, ".") {
|
||||||
|
if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
|
||||||
|
postgresUseOriginalTerm = true
|
||||||
|
} else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL {
|
||||||
|
lastIndex := strings.LastIndex(term, ".")
|
||||||
|
term = term[0:lastIndex]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// these chars have special meaning and can be treated as spaces
|
// these chars have special meaning and can be treated as spaces
|
||||||
for _, c := range specialUserSearchChar {
|
for _, c := range specialUserSearchChar {
|
||||||
term = strings.Replace(term, c, " ", -1)
|
term = strings.Replace(term, c, " ", -1)
|
||||||
@@ -1323,6 +1343,13 @@ func (us SqlUserStore) performSearch(searchQuery string, term string, options ma
|
|||||||
if term == "" {
|
if term == "" {
|
||||||
searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", "", 1)
|
searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", "", 1)
|
||||||
} else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
|
} else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
|
||||||
|
if postgresUseOriginalTerm {
|
||||||
|
term = originalTerm
|
||||||
|
// these chars will break the query and must be removed
|
||||||
|
for _, c := range postgresSearchChar {
|
||||||
|
term = strings.Replace(term, c, "", -1)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
splitTerm := strings.Fields(term)
|
splitTerm := strings.Fields(term)
|
||||||
for i, t := range strings.Fields(term) {
|
for i, t := range strings.Fields(term) {
|
||||||
if i == len(splitTerm)-1 {
|
if i == len(splitTerm)-1 {
|
||||||
@@ -1333,6 +1360,7 @@ func (us SqlUserStore) performSearch(searchQuery string, term string, options ma
|
|||||||
}
|
}
|
||||||
|
|
||||||
term = strings.Join(splitTerm, " ")
|
term = strings.Join(splitTerm, " ")
|
||||||
|
}
|
||||||
|
|
||||||
searchType = convertMySQLFullTextColumnsToPostgres(searchType)
|
searchType = convertMySQLFullTextColumnsToPostgres(searchType)
|
||||||
searchClause := fmt.Sprintf("AND (%s) @@ to_tsquery('simple', :Term)", searchType)
|
searchClause := fmt.Sprintf("AND (%s) @@ to_tsquery('simple', :Term)", searchType)
|
||||||
|
|||||||
@@ -986,7 +986,7 @@ func TestUserStoreSearch(t *testing.T) {
|
|||||||
u1.FirstName = "Tim"
|
u1.FirstName = "Tim"
|
||||||
u1.LastName = "Bill"
|
u1.LastName = "Bill"
|
||||||
u1.Nickname = "Rob"
|
u1.Nickname = "Rob"
|
||||||
u1.Email = "harold" + model.NewId()
|
u1.Email = "harold" + model.NewId() + "@simulator.amazonses.com"
|
||||||
Must(store.User().Save(u1))
|
Must(store.User().Save(u1))
|
||||||
|
|
||||||
u2 := &model.User{}
|
u2 := &model.User{}
|
||||||
@@ -1033,6 +1033,26 @@ func TestUserStoreSearch(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
searchOptions[USER_SEARCH_OPTION_NAMES_ONLY] = false
|
||||||
|
|
||||||
|
if r1 := <-store.User().Search(tid, u1.Email, searchOptions); r1.Err != nil {
|
||||||
|
t.Fatal(r1.Err)
|
||||||
|
} else {
|
||||||
|
profiles := r1.Data.([]*model.User)
|
||||||
|
found1 := false
|
||||||
|
for _, profile := range profiles {
|
||||||
|
if profile.Id == u1.Id {
|
||||||
|
found1 = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !found1 {
|
||||||
|
t.Fatal("should have found user")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
searchOptions[USER_SEARCH_OPTION_NAMES_ONLY] = true
|
||||||
|
|
||||||
// * should be treated as a space
|
// * should be treated as a space
|
||||||
if r1 := <-store.User().Search(tid, "jimb*", searchOptions); r1.Err != nil {
|
if r1 := <-store.User().Search(tid, "jimb*", searchOptions); r1.Err != nil {
|
||||||
t.Fatal(r1.Err)
|
t.Fatal(r1.Err)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user