From 9992a27a907ba5472ff738b54131013689605c6c Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Wed, 17 Feb 2021 13:52:15 +0530 Subject: [PATCH] Revert "MM-24530-Add support for search terms with underscore using postgresql engine (#16618)" (#16950) This reverts commit ba3b788e46f98e2c2d7976d8d264a364676c9b2b. --- api4/post_test.go | 21 --------------------- store/searchtest/post_layer.go | 2 +- store/sqlstore/post_store.go | 11 +---------- 3 files changed, 2 insertions(+), 32 deletions(-) diff --git a/api4/post_test.go b/api4/post_test.go index 351139ae27..1e6e4c5cd4 100644 --- a/api4/post_test.go +++ b/api4/post_test.go @@ -2249,27 +2249,6 @@ 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() diff --git a/store/searchtest/post_layer.go b/store/searchtest/post_layer.go index 40d2be566a..31f8140e43 100644 --- a/store/searchtest/post_layer.go +++ b/store/searchtest/post_layer.go @@ -215,7 +215,7 @@ var searchPostStoreTests = []searchTest{ { Name: "Should be able to search terms with underscores", Fn: testSearchTermsWithUnderscores, - Tags: []string{EngineAll}, + Tags: []string{EngineMySql, EngineElasticSearch}, }, { Name: "Should be able to search posts made by bot accounts", diff --git a/store/sqlstore/post_store.go b/store/sqlstore/post_store.go index b94420fda6..7e84ad3408 100644 --- a/store/sqlstore/post_store.go +++ b/store/sqlstore/post_store.go @@ -1487,16 +1487,7 @@ func (s *SqlPostStore) search(teamId string, userId string, params *model.Search queryParams["Terms"] = "(" + strings.Join(strings.Fields(terms), " & ") + ")" + excludeClause } - 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) - } + 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" {