PLT-8312: Use combined LIKE/Full Text search for channels. (#8029)

* PLT-8312: Use combined LIKE/Full Text search for channels.

* Code tidyup

* Get it working consistently and update unit tests.

* Fix code style.
This commit is contained in:
George Goldberg
2018-01-05 15:59:10 +00:00
committed by Saturnino Abril
parent a5bbf3f643
commit 143e664cd9
3 changed files with 142 additions and 26 deletions

View File

@@ -1022,15 +1022,30 @@ func (us SqlUserStore) SearchInChannel(channelId string, term string, options ma
})
}
var escapeUserSearchChar = []string{
var escapeLikeSearchChar = []string{
"%",
"_",
}
var ignoreUserSearchChar = []string{
var ignoreLikeSearchChar = []string{
"*",
}
var spaceFulltextSearchChar = []string{
"<",
">",
"+",
"-",
"(",
")",
"~",
":",
"*",
"\"",
"!",
"@",
}
func generateSearchQuery(searchQuery string, terms []string, fields []string, parameters map[string]interface{}, isPostgreSQL bool) string {
searchTerms := []string{}
for i, term := range terms {
@@ -1054,12 +1069,12 @@ func (us SqlUserStore) performSearch(searchQuery string, term string, options ma
result := store.StoreResult{}
// These chars must be removed from the like query.
for _, c := range ignoreUserSearchChar {
for _, c := range ignoreLikeSearchChar {
term = strings.Replace(term, c, "", -1)
}
// These chars must be escaped in the like query.
for _, c := range escapeUserSearchChar {
for _, c := range escapeLikeSearchChar {
term = strings.Replace(term, c, "*"+c, -1)
}