mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Fix the multiple column full text search index for Postgres (#4282)
This commit is contained in:
@@ -483,7 +483,8 @@ func (ss SqlStore) createIndexIfNotExists(indexName string, tableName string, co
|
||||
|
||||
query := ""
|
||||
if indexType == INDEX_TYPE_FULL_TEXT {
|
||||
query = "CREATE INDEX " + indexName + " ON " + tableName + " USING gin(to_tsvector('english', " + columnName + "))"
|
||||
postgresColumnNames := convertMySQLFullTextColumnsToPostgres(columnName)
|
||||
query = "CREATE INDEX " + indexName + " ON " + tableName + " USING gin(to_tsvector('english', " + postgresColumnNames + "))"
|
||||
} else {
|
||||
query = "CREATE " + uniqueStr + "INDEX " + indexName + " ON " + tableName + " (" + columnName + ")"
|
||||
}
|
||||
@@ -745,6 +746,19 @@ func (me mattermConverter) FromDb(target interface{}) (gorp.CustomScanner, bool)
|
||||
return gorp.CustomScanner{}, false
|
||||
}
|
||||
|
||||
func convertMySQLFullTextColumnsToPostgres(columnNames string) string {
|
||||
columns := strings.Split(columnNames, ", ")
|
||||
concatenatedColumnNames := ""
|
||||
for i, c := range columns {
|
||||
concatenatedColumnNames += c
|
||||
if i < len(columns)-1 {
|
||||
concatenatedColumnNames += " || ' ' || "
|
||||
}
|
||||
}
|
||||
|
||||
return concatenatedColumnNames
|
||||
}
|
||||
|
||||
func encrypt(key []byte, text string) (string, error) {
|
||||
|
||||
if text == "" || text == "{}" {
|
||||
|
||||
@@ -1195,6 +1195,7 @@ func (us SqlUserStore) performSearch(searchQuery string, term string, searchType
|
||||
searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", "", 1)
|
||||
} else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
|
||||
term = term + ":*"
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user