diff options
author | Joram Wilander <jwawilander@gmail.com> | 2016-10-31 09:10:20 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-10-31 09:10:20 -0400 |
commit | 4887c9228cb90d6a9bfe57c7e21aa507958de4f3 (patch) | |
tree | 73fd963f7e8d22954a8ec60e8afce6807f72c7a1 /store/sql_user_store.go | |
parent | 60a92f0a270bcef2ee8560bdd276aadd8fdd3697 (diff) | |
download | chat-4887c9228cb90d6a9bfe57c7e21aa507958de4f3.tar.gz chat-4887c9228cb90d6a9bfe57c7e21aa507958de4f3.tar.bz2 chat-4887c9228cb90d6a9bfe57c7e21aa507958de4f3.zip |
Fix user autocomplete with special characters (#4373)
Diffstat (limited to 'store/sql_user_store.go')
-rw-r--r-- | store/sql_user_store.go | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go index c1fb9b28d..4f5e11d00 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -1196,15 +1196,36 @@ func (us SqlUserStore) SearchInChannel(channelId string, term string, searchType func (us SqlUserStore) performSearch(searchQuery string, term string, searchType string, parameters map[string]interface{}) StoreResult { result := StoreResult{} + // these chars have special meaning and can be treated as spaces + for _, c := range specialSearchChar { + term = strings.Replace(term, c, " ", -1) + } + if term == "" { searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", "", 1) } else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES { - term = term + ":*" + splitTerm := strings.Fields(term) + for i, t := range strings.Fields(term) { + if i == len(splitTerm)-1 { + splitTerm[i] = t + ":*" + } else { + splitTerm[i] = t + ":* &" + } + } + + term = strings.Join(splitTerm, " ") + searchType = convertMySQLFullTextColumnsToPostgres(searchType) searchClause := fmt.Sprintf("AND (%s) @@ to_tsquery(:Term)", searchType) searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", searchClause, 1) } else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL { - term = term + "*" + splitTerm := strings.Fields(term) + for i, t := range strings.Fields(term) { + splitTerm[i] = "+" + t + "*" + } + + term = strings.Join(splitTerm, " ") + searchClause := fmt.Sprintf("AND MATCH(%s) AGAINST (:Term IN BOOLEAN MODE)", searchType) searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", searchClause, 1) } |