summaryrefslogtreecommitdiffstats
path: root/store/sqlstore/user_store.go
diff options
context:
space:
mode:
Diffstat (limited to 'store/sqlstore/user_store.go')
-rw-r--r--store/sqlstore/user_store.go43
1 files changed, 24 insertions, 19 deletions
diff --git a/store/sqlstore/user_store.go b/store/sqlstore/user_store.go
index aba7c56a3..3fafc7eab 100644
--- a/store/sqlstore/user_store.go
+++ b/store/sqlstore/user_store.go
@@ -1028,6 +1028,28 @@ var ignoreUserSearchChar = []string{
"*",
}
+func generateSearchQuery(searchQuery, term, searchField string, parameters map[string]interface{}, isPostgreSQL bool) string {
+ splitTerms := strings.Fields(term)
+ splitFields := strings.Split(searchField, ", ")
+
+ terms := []string{}
+ for i, term := range splitTerms {
+ fields := []string{}
+ for _, field := range splitFields {
+ if isPostgreSQL {
+ fields = append(fields, fmt.Sprintf("lower(%s) LIKE lower(%s) escape '*' ", field, fmt.Sprintf(":Term%d", i)))
+ } else {
+ fields = append(fields, fmt.Sprintf("%s LIKE %s escape '*' ", field, fmt.Sprintf(":Term%d", i)))
+ }
+ }
+ terms = append(terms, fmt.Sprintf("(%s)", strings.Join(fields, " OR ")))
+ parameters[fmt.Sprintf("Term%d", i)] = fmt.Sprintf("%s%%", term)
+ }
+
+ searchClause := strings.Join(terms, " AND ")
+ return strings.Replace(searchQuery, "SEARCH_CLAUSE", fmt.Sprintf(" AND %s ", searchClause), 1)
+}
+
func (us SqlUserStore) performSearch(searchQuery string, term string, options map[string]bool, parameters map[string]interface{}) store.StoreResult {
result := store.StoreResult{}
@@ -1059,25 +1081,8 @@ func (us SqlUserStore) performSearch(searchQuery string, term string, options ma
if term == "" {
searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", "", 1)
} else {
- splitTerms := strings.Fields(term)
- splitFields := strings.Split(searchType, ", ")
-
- terms := []string{}
- for i, term := range splitTerms {
- fields := []string{}
- for _, field := range splitFields {
- if us.DriverName() == model.DATABASE_DRIVER_POSTGRES {
- fields = append(fields, fmt.Sprintf("lower(%s) LIKE lower(%s) escape '*' ", field, fmt.Sprintf(":Term%d", i)))
- } else {
- fields = append(fields, fmt.Sprintf("%s LIKE %s escape '*' ", field, fmt.Sprintf(":Term%d", i)))
- }
- }
- terms = append(terms, fmt.Sprintf("(%s)", strings.Join(fields, " OR ")))
- parameters[fmt.Sprintf("Term%d", i)] = fmt.Sprintf("%s%%", term)
- }
-
- term := strings.Join(terms, " AND ")
- searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", fmt.Sprintf(" AND %s ", term), 1)
+ isPostgreSQL := us.DriverName() == model.DATABASE_DRIVER_POSTGRES
+ searchQuery = generateSearchQuery(searchQuery, term, searchType, parameters, isPostgreSQL)
}
var users []*model.User