store/post: fix searching for phrases in postgres (#17042)

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2021-03-22 11:03:26 +03:00
коммит произвёл GitHub
родитель 33e319366c
Коммит 35cfab33fc
2 изменённых файлов: 7 добавлений и 0 удалений

Просмотреть файл

@@ -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\""}

Просмотреть файл

@@ -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
}