summaryrefslogtreecommitdiffstats
path: root/store/sqlstore/channel_store_experimental.go
diff options
context:
space:
mode:
authorJesús Espino <jespinog@gmail.com>2018-09-27 16:15:41 +0200
committerCarlos Tadeu Panato Junior <ctadeu@gmail.com>2018-09-27 16:15:41 +0200
commit49e0473753c2e4e2e02e30c17a7793657b71363f (patch)
tree944fe36b0a1982705b2fa98da466867285d00652 /store/sqlstore/channel_store_experimental.go
parent89852d04c064588f24c6122caf18b8e656399f94 (diff)
downloadchat-49e0473753c2e4e2e02e30c17a7793657b71363f.tar.gz
chat-49e0473753c2e4e2e02e30c17a7793657b71363f.tar.bz2
chat-49e0473753c2e4e2e02e30c17a7793657b71363f.zip
MM-11567: Autocomplete search in: for DMs and GMs (#9430)
* MM-11567: Autocomplete search in: for DMs and GMs * Adding unit tests * Allowing to search Direct Messages in the autocompletion * Fix it in TE
Diffstat (limited to 'store/sqlstore/channel_store_experimental.go')
-rw-r--r--store/sqlstore/channel_store_experimental.go19
1 files changed, 8 insertions, 11 deletions
diff --git a/store/sqlstore/channel_store_experimental.go b/store/sqlstore/channel_store_experimental.go
index 7cf142aba..164622654 100644
--- a/store/sqlstore/channel_store_experimental.go
+++ b/store/sqlstore/channel_store_experimental.go
@@ -555,14 +555,14 @@ func (s SqlChannelStoreExperimental) AutocompleteInTeam(teamId string, term stri
var channels model.ChannelList
- if likeClause, likeTerm := s.buildLIKEClause(term); likeClause == "" {
+ if likeClause, likeTerm := s.buildLIKEClause(term, "c.Name, c.DisplayName, c.Purpose"); likeClause == "" {
if _, err := s.GetReplica().Select(&channels, fmt.Sprintf(queryFormat, ""), map[string]interface{}{"TeamId": teamId}); err != nil {
result.Err = model.NewAppError("SqlChannelStore.AutocompleteInTeam", "store.sql_channel.search.app_error", nil, "term="+term+", "+", "+err.Error(), http.StatusInternalServerError)
}
} else {
// Using a UNION results in index_merge and fulltext queries and is much faster than the ref
// query you would get using an OR of the LIKE and full-text clauses.
- fulltextClause, fulltextTerm := s.buildFulltextClause(term)
+ fulltextClause, fulltextTerm := s.buildFulltextClause(term, "c.Name, c.DisplayName, c.Purpose")
likeQuery := fmt.Sprintf(queryFormat, "AND "+likeClause)
fulltextQuery := fmt.Sprintf(queryFormat, "AND "+fulltextClause)
query := fmt.Sprintf("(%v) UNION (%v) LIMIT 50", likeQuery, fulltextQuery)
@@ -647,13 +647,12 @@ func (s SqlChannelStoreExperimental) SearchMore(userId string, teamId string, te
})
}
-func (s SqlChannelStoreExperimental) buildLIKEClause(term string) (likeClause, likeTerm string) {
+func (s SqlChannelStoreExperimental) buildLIKEClause(term string, searchColumns string) (likeClause, likeTerm string) {
if !s.IsExperimentalPublicChannelsMaterializationEnabled() {
- return s.SqlChannelStore.buildLIKEClause(term)
+ return s.SqlChannelStore.buildLIKEClause(term, searchColumns)
}
likeTerm = term
- searchColumns := "c.Name, c.DisplayName, c.Purpose"
// These chars must be removed from the like query.
for _, c := range ignoreLikeSearchChar {
@@ -684,16 +683,14 @@ func (s SqlChannelStoreExperimental) buildLIKEClause(term string) (likeClause, l
return
}
-func (s SqlChannelStoreExperimental) buildFulltextClause(term string) (fulltextClause, fulltextTerm string) {
+func (s SqlChannelStoreExperimental) buildFulltextClause(term string, searchColumns string) (fulltextClause, fulltextTerm string) {
if !s.IsExperimentalPublicChannelsMaterializationEnabled() {
- return s.SqlChannelStore.buildFulltextClause(term)
+ return s.SqlChannelStore.buildFulltextClause(term, searchColumns)
}
// Copy the terms as we will need to prepare them differently for each search type.
fulltextTerm = term
- searchColumns := "c.Name, c.DisplayName, c.Purpose"
-
// These chars must be treated as spaces in the fulltext query.
for _, c := range spaceFulltextSearchChar {
fulltextTerm = strings.Replace(fulltextTerm, c, " ", -1)
@@ -736,13 +733,13 @@ func (s SqlChannelStoreExperimental) performSearch(searchQuery string, term stri
result := store.StoreResult{}
- likeClause, likeTerm := s.buildLIKEClause(term)
+ likeClause, likeTerm := s.buildLIKEClause(term, "c.Name, c.DisplayName, c.Purpose")
if likeTerm == "" {
// If the likeTerm is empty after preparing, then don't bother searching.
searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", "", 1)
} else {
parameters["LikeTerm"] = likeTerm
- fulltextClause, fulltextTerm := s.buildFulltextClause(term)
+ fulltextClause, fulltextTerm := s.buildFulltextClause(term, "c.Name, c.DisplayName, c.Purpose")
parameters["FulltextTerm"] = fulltextTerm
searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", "AND ("+likeClause+" OR "+fulltextClause+")", 1)
}