MM-24530-Add support for search terms with underscore using postgresql engine (#16618)
* add support for search terms with underscore using postgresql * fix failing tests Initially issue fix applied to all search terms instead of the ones that contains _ * direct cast tsquery * fix test issues * refactor underscored quoted term search * support search term case-insensitive Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3da6f270ec
Коммит
ba3b788e46
@@ -2249,6 +2249,27 @@ func TestSearchHashtagPosts(t *testing.T) {
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
|
||||
func TestSearchUnderscorePosts(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
th.LoginBasic()
|
||||
Client := th.Client
|
||||
|
||||
message := "test_with_underscore"
|
||||
assert.NotNil(t, th.CreateMessagePost(message))
|
||||
|
||||
message = " test with underscore"
|
||||
assert.NotNil(t, th.CreateMessagePost(message))
|
||||
|
||||
posts, resp := Client.SearchPosts(th.BasicTeam.Id, "test_with_underscore", false)
|
||||
CheckNoError(t, resp)
|
||||
require.Len(t, posts.Order, 1, "wrong search results")
|
||||
|
||||
Client.Logout()
|
||||
_, resp = Client.SearchPosts(th.BasicTeam.Id, "#sgtitlereview", false)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
|
||||
func TestSearchPostsInChannel(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
@@ -215,7 +215,7 @@ var searchPostStoreTests = []searchTest{
|
||||
{
|
||||
Name: "Should be able to search terms with underscores",
|
||||
Fn: testSearchTermsWithUnderscores,
|
||||
Tags: []string{EngineMySql, EngineElasticSearch},
|
||||
Tags: []string{EngineAll},
|
||||
},
|
||||
{
|
||||
Name: "Should be able to search posts made by bot accounts",
|
||||
|
||||
@@ -1481,7 +1481,16 @@ func (s *SqlPostStore) search(teamId string, userId string, params *model.Search
|
||||
queryParams["Terms"] = "(" + strings.Join(strings.Fields(terms), " & ") + ")" + excludeClause
|
||||
}
|
||||
|
||||
searchClause := fmt.Sprintf("AND to_tsvector('english', %s) @@ to_tsquery('english', :Terms)", searchType)
|
||||
searchClause := ""
|
||||
if strings.Contains(terms, "_") {
|
||||
//Strip quotes off terms with it
|
||||
if strings.Contains(terms, "\"") {
|
||||
queryParams["Terms"] = strings.ReplaceAll(queryParams["Terms"].(string), "\"", "")
|
||||
}
|
||||
searchClause = fmt.Sprintf("AND lower(%s)::tsvector @@ lower(:Terms)::tsquery", searchType)
|
||||
} else {
|
||||
searchClause = fmt.Sprintf("AND to_tsvector('english', %s) @@ to_tsquery('english', :Terms)", searchType)
|
||||
}
|
||||
searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", searchClause, 1)
|
||||
} else if s.DriverName() == model.DATABASE_DRIVER_MYSQL {
|
||||
if searchType == "Message" {
|
||||
|
||||
Ссылка в новой задаче
Block a user