From 35cfab33fcd07fb4f846d474a4b95af20f7eb492 Mon Sep 17 00:00:00 2001 From: Ibrahim Serdar Acikgoz Date: Mon, 22 Mar 2021 11:03:26 +0300 Subject: [PATCH] store/post: fix searching for phrases in postgres (#17042) Co-authored-by: Mattermod --- store/searchtest/post_layer.go | 5 +++++ store/sqlstore/post_store.go | 2 ++ 2 files changed, 7 insertions(+) diff --git a/store/searchtest/post_layer.go b/store/searchtest/post_layer.go index 31f8140e43..89e229e0c8 100644 --- a/store/searchtest/post_layer.go +++ b/store/searchtest/post_layer.go @@ -345,6 +345,11 @@ func testSearchExactPhraseInQuotes(t *testing.T, th *SearchTestHelper) { require.NoError(t, err) _, err = th.createPost(th.User.Id, th.ChannelBasic.Id, "channel test 123", "", model.POST_DEFAULT, 0, false) require.NoError(t, err) + _, err = th.createPost(th.User.Id, th.ChannelBasic.Id, "channel something test 1 2 3", "", model.POST_DEFAULT, 0, false) + require.NoError(t, err) + _, err = th.createPost(th.User.Id, th.ChannelBasic.Id, "channel 1 2 3", "", model.POST_DEFAULT, 0, false) + require.NoError(t, err) + defer th.deleteUserPosts(th.User.Id) params := &model.SearchParams{Terms: "\"channel test 1 2 3\""} diff --git a/store/sqlstore/post_store.go b/store/sqlstore/post_store.go index 5bcec93226..f769f1ac11 100644 --- a/store/sqlstore/post_store.go +++ b/store/sqlstore/post_store.go @@ -1490,6 +1490,8 @@ func (s *SqlPostStore) search(teamId string, userId string, params *model.Search if params.OrTerms { queryParams["Terms"] = "(" + strings.Join(strings.Fields(terms), " | ") + ")" + excludeClause + } else if strings.HasPrefix(terms, `"`) && strings.HasSuffix(terms, `"`) { + queryParams["Terms"] = "(" + strings.Join(strings.Fields(terms), " <-> ") + ")" + excludeClause } else { queryParams["Terms"] = "(" + strings.Join(strings.Fields(terms), " & ") + ")" + excludeClause }