PLT-5612: Don't show error on invalid search query. (#5596)
Log a warning to the logs, but don't show an error to the user in the WebUI, just an empty set of query results, when the fulltext search query they enter generates a syntax error from the database.
Этот коммит содержится в:
коммит произвёл
Corey Hulen
родитель
d945393403
Коммит
2e5ebac615
@@ -5032,8 +5032,8 @@
|
|||||||
"translation": "You cannot update an existing Post"
|
"translation": "You cannot update an existing Post"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "store.sql_post.search.app_error",
|
"id": "store.sql_post.search.warn",
|
||||||
"translation": "We encountered an error while searching for posts"
|
"translation": "Query error searching posts: %v"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "store.sql_post.update.app_error",
|
"id": "store.sql_post.update.app_error",
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
l4g "github.com/alecthomas/log4go"
|
||||||
"github.com/mattermost/platform/einterfaces"
|
"github.com/mattermost/platform/einterfaces"
|
||||||
"github.com/mattermost/platform/model"
|
"github.com/mattermost/platform/model"
|
||||||
"github.com/mattermost/platform/utils"
|
"github.com/mattermost/platform/utils"
|
||||||
@@ -961,27 +962,28 @@ func (s SqlPostStore) Search(teamId string, userId string, params *model.SearchP
|
|||||||
|
|
||||||
queryParams["Terms"] = terms
|
queryParams["Terms"] = terms
|
||||||
|
|
||||||
_, err := s.GetReplica().Select(&posts, searchQuery, queryParams)
|
|
||||||
if err != nil {
|
|
||||||
result.Err = model.NewLocAppError("SqlPostStore.Search", "store.sql_post.search.app_error", nil, "teamId="+teamId+", err="+err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
list := model.NewPostList()
|
list := model.NewPostList()
|
||||||
|
|
||||||
for _, p := range posts {
|
_, err := s.GetReplica().Select(&posts, searchQuery, queryParams)
|
||||||
if searchType == "Hashtags" {
|
if err != nil {
|
||||||
exactMatch := false
|
l4g.Warn(utils.T("store.sql_post.search.warn"), err.Error())
|
||||||
for _, tag := range strings.Split(p.Hashtags, " ") {
|
// Don't return the error to the caller as it is of no use to the user. Instead return an empty set of search results.
|
||||||
if termMap[strings.ToUpper(tag)] {
|
} else {
|
||||||
exactMatch = true
|
for _, p := range posts {
|
||||||
|
if searchType == "Hashtags" {
|
||||||
|
exactMatch := false
|
||||||
|
for _, tag := range strings.Split(p.Hashtags, " ") {
|
||||||
|
if termMap[strings.ToUpper(tag)] {
|
||||||
|
exactMatch = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !exactMatch {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !exactMatch {
|
list.AddPost(p)
|
||||||
continue
|
list.AddOrder(p.Id)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
list.AddPost(p)
|
|
||||||
list.AddOrder(p.Id)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
list.MakeNonNil()
|
list.MakeNonNil()
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user