Adding the ability to disable full text search queries for master (#6102)

This commit is contained in:
Corey Hulen
2017-04-17 07:54:26 -07:00
committed by Christopher Speller
parent 7e29dc65aa
commit 3207886514
5 changed files with 33 additions and 0 deletions

View File

@@ -41,6 +41,7 @@
"AllowEditPost": "always",
"PostEditTimeLimit": 300,
"TimeBetweenUserTypingUpdatesMilliseconds": 5000,
"EnablePostSearch": true,
"EnableUserTypingMessages": true,
"ClusterLogTimeoutMilliseconds": 2000
},

View File

@@ -5203,6 +5203,10 @@
"id": "store.sql_post.search.warn",
"translation": "Query error searching posts: %v"
},
{
"id": "store.sql_post.search.disabled",
"translation": "Searching has been disabled on this server. Please contact your System Administrator."
},
{
"id": "store.sql_post.update.app_error",
"translation": "We couldn't update the Post"

View File

@@ -151,6 +151,7 @@ type ServiceSettings struct {
AllowEditPost *string
PostEditTimeLimit *int
TimeBetweenUserTypingUpdatesMilliseconds *int64
EnablePostSearch *bool
EnableUserTypingMessages *bool
ClusterLogTimeoutMilliseconds *int
}
@@ -1148,6 +1149,11 @@ func (o *Config) SetDefaults() {
*o.ServiceSettings.TimeBetweenUserTypingUpdatesMilliseconds = 5000
}
if o.ServiceSettings.EnablePostSearch == nil {
o.ServiceSettings.EnablePostSearch = new(bool)
*o.ServiceSettings.EnablePostSearch = true
}
if o.ServiceSettings.EnableUserTypingMessages == nil {
o.ServiceSettings.EnableUserTypingMessages = new(bool)
*o.ServiceSettings.EnableUserTypingMessages = true

View File

@@ -4,6 +4,7 @@
package model
import (
"encoding/json"
"regexp"
"strings"
)
@@ -19,6 +20,15 @@ type SearchParams struct {
OrTerms bool
}
func (o *SearchParams) ToJson() string {
b, err := json.Marshal(o)
if err != nil {
return ""
} else {
return string(b)
}
}
var searchFlags = [...]string{"from", "channel", "in"}
func splitWordsNoQuotes(text string) []string {

View File

@@ -908,6 +908,17 @@ func (s SqlPostStore) Search(teamId string, userId string, params *model.SearchP
go func() {
result := StoreResult{}
if !*utils.Cfg.ServiceSettings.EnablePostSearch {
list := &model.PostList{}
list.MakeNonNil()
result.Data = list
result.Err = model.NewLocAppError("SqlPostStore.Search", "store.sql_post.search.disabled", nil, fmt.Sprintf("teamId=%v userId=%v params=%v", teamId, userId, params.ToJson()))
storeChannel <- result
close(storeChannel)
return
}
queryParams := map[string]interface{}{
"TeamId": teamId,
"UserId": userId,
@@ -919,6 +930,7 @@ func (s SqlPostStore) Search(teamId string, userId string, params *model.SearchP
if terms == "" && len(params.InChannels) == 0 && len(params.FromUsers) == 0 {
result.Data = []*model.Post{}
storeChannel <- result
close(storeChannel)
return
}