[MM-24522] remove duplication in OR and IncludeDeletedChannels params for search (#14573)

Этот коммит содержится в:
Abdulkadir Poyraz
2020-08-31 14:40:58 +03:00
коммит произвёл GitHub
родитель 2b1da58e6d
Коммит f12ca27bac
12 изменённых файлов: 182 добавлений и 132 удалений

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

@@ -1079,6 +1079,7 @@ func (a *App) SearchPostsInTeamForUser(terms string, userId string, teamId strin
for _, params := range paramsList { for _, params := range paramsList {
params.OrTerms = isOrSearch params.OrTerms = isOrSearch
params.IncludeDeletedChannels = includeDeleted
// Don't allow users to search for "*" // Don't allow users to search for "*"
if params.Terms != "*" { if params.Terms != "*" {
// Convert channel names to channel IDs // Convert channel names to channel IDs
@@ -1098,7 +1099,7 @@ func (a *App) SearchPostsInTeamForUser(terms string, userId string, teamId strin
return model.MakePostSearchResults(model.NewPostList(), nil), nil return model.MakePostSearchResults(model.NewPostList(), nil), nil
} }
postSearchResults, err = a.Srv().Store.Post().SearchPostsInTeamForUser(finalParamsList, userId, teamId, isOrSearch, includeDeleted, page, perPage) postSearchResults, err = a.Srv().Store.Post().SearchPostsInTeamForUser(finalParamsList, userId, teamId, page, perPage)
if err != nil { if err != nil {
return nil, err return nil, err
} }

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

@@ -6778,6 +6778,10 @@
"id": "model.reaction.is_valid.user_id.app_error", "id": "model.reaction.is_valid.user_id.app_error",
"translation": "Invalid user id." "translation": "Invalid user id."
}, },
{
"id": "model.search_params_list.is_valid.include_deleted_channels.app_error",
"translation": "All IncludeDeletedChannels params should have the same value."
},
{ {
"id": "model.team.is_valid.characters.app_error", "id": "model.team.is_valid.characters.app_error",
"translation": "Name must be 2 or more lowercase alphanumeric characters." "translation": "Name must be 2 or more lowercase alphanumeric characters."

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

@@ -4,6 +4,7 @@
package model package model
import ( import (
"net/http"
"regexp" "regexp"
"strings" "strings"
"time" "time"
@@ -367,3 +368,13 @@ func ParseSearchParams(text string, timeZoneOffset int) []*SearchParams {
return paramsList return paramsList
} }
func IsSearchParamsListValid(paramsList []*SearchParams) *AppError {
// All SearchParams should have same IncludeDeletedChannels value.
for _, params := range paramsList {
if params.IncludeDeletedChannels != paramsList[0].IncludeDeletedChannels {
return NewAppError("IsSearchParamsListValid", "model.search_params_list.is_valid.include_deleted_channels.app_error", nil, "", http.StatusInternalServerError)
}
}
return nil
}

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

@@ -1618,3 +1618,19 @@ func TestGetAfterDateMillis(t *testing.T) {
}) })
} }
} }
func TestIsSearchParamsListValid(t *testing.T) {
var err *AppError
err = IsSearchParamsListValid([]*SearchParams{{IncludeDeletedChannels: true}, {IncludeDeletedChannels: true}})
assert.Nil(t, err)
err = IsSearchParamsListValid([]*SearchParams{{IncludeDeletedChannels: true}, {IncludeDeletedChannels: false}})
assert.NotNil(t, err)
err = IsSearchParamsListValid([]*SearchParams{{IncludeDeletedChannels: true}})
assert.Nil(t, err)
err = IsSearchParamsListValid([]*SearchParams{})
assert.Nil(t, err)
}

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

@@ -5329,7 +5329,7 @@ func (s *OpenTracingLayerPostStore) Search(teamId string, userId string, params
return result, err return result, err
} }
func (s *OpenTracingLayerPostStore) SearchPostsInTeamForUser(paramsList []*model.SearchParams, userId string, teamId string, isOrSearch bool, includeDeletedChannels bool, page int, perPage int) (*model.PostSearchResults, *model.AppError) { func (s *OpenTracingLayerPostStore) SearchPostsInTeamForUser(paramsList []*model.SearchParams, userId string, teamId string, page int, perPage int) (*model.PostSearchResults, *model.AppError) {
origCtx := s.Root.Store.Context() origCtx := s.Root.Store.Context()
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.SearchPostsInTeamForUser") span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "PostStore.SearchPostsInTeamForUser")
s.Root.Store.SetContext(newCtx) s.Root.Store.SetContext(newCtx)
@@ -5338,7 +5338,7 @@ func (s *OpenTracingLayerPostStore) SearchPostsInTeamForUser(paramsList []*model
}() }()
defer span.Finish() defer span.Finish()
result, err := s.PostStore.SearchPostsInTeamForUser(paramsList, userId, teamId, isOrSearch, includeDeletedChannels, page, perPage) result, err := s.PostStore.SearchPostsInTeamForUser(paramsList, userId, teamId, page, perPage)
if err != nil { if err != nil {
span.LogFields(spanlog.Error(err)) span.LogFields(spanlog.Error(err))
ext.Error.Set(span, true) ext.Error.Set(span, true)

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

@@ -3860,9 +3860,9 @@ func (s *RetryLayerPostStore) Search(teamId string, userId string, params *model
} }
func (s *RetryLayerPostStore) SearchPostsInTeamForUser(paramsList []*model.SearchParams, userId string, teamId string, isOrSearch bool, includeDeletedChannels bool, page int, perPage int) (*model.PostSearchResults, *model.AppError) { func (s *RetryLayerPostStore) SearchPostsInTeamForUser(paramsList []*model.SearchParams, userId string, teamId string, page int, perPage int) (*model.PostSearchResults, *model.AppError) {
return s.PostStore.SearchPostsInTeamForUser(paramsList, userId, teamId, isOrSearch, includeDeletedChannels, page, perPage) return s.PostStore.SearchPostsInTeamForUser(paramsList, userId, teamId, page, perPage)
} }

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

@@ -131,9 +131,13 @@ func (s SearchPostStore) PermanentDeleteByChannel(channelID string) error {
return err return err
} }
func (s SearchPostStore) searchPostsInTeamForUserByEngine(engine searchengine.SearchEngineInterface, paramsList []*model.SearchParams, userId, teamId string, isOrSearch, includeDeletedChannels bool, page, perPage int) (*model.PostSearchResults, *model.AppError) { func (s SearchPostStore) searchPostsInTeamForUserByEngine(engine searchengine.SearchEngineInterface, paramsList []*model.SearchParams, userId, teamId string, page, perPage int) (*model.PostSearchResults, *model.AppError) {
if err := model.IsSearchParamsListValid(paramsList); err != nil {
return nil, err
}
// We only allow the user to search in channels they are a member of. // We only allow the user to search in channels they are a member of.
userChannels, nErr := s.rootStore.Channel().GetChannels(teamId, userId, includeDeletedChannels, 0) userChannels, nErr := s.rootStore.Channel().GetChannels(teamId, userId, paramsList[0].IncludeDeletedChannels, 0)
if nErr != nil { if nErr != nil {
mlog.Error("error getting channel for user", mlog.Err(nErr)) mlog.Error("error getting channel for user", mlog.Err(nErr))
var nfErr *store.ErrNotFound var nfErr *store.ErrNotFound
@@ -169,10 +173,10 @@ func (s SearchPostStore) searchPostsInTeamForUserByEngine(engine searchengine.Se
return model.MakePostSearchResults(postList, matches), nil return model.MakePostSearchResults(postList, matches), nil
} }
func (s SearchPostStore) SearchPostsInTeamForUser(paramsList []*model.SearchParams, userId, teamId string, isOrSearch, includeDeletedChannels bool, page, perPage int) (*model.PostSearchResults, *model.AppError) { func (s SearchPostStore) SearchPostsInTeamForUser(paramsList []*model.SearchParams, userId, teamId string, page, perPage int) (*model.PostSearchResults, *model.AppError) {
for _, engine := range s.rootStore.searchEngine.GetActiveEngines() { for _, engine := range s.rootStore.searchEngine.GetActiveEngines() {
if engine.IsSearchEnabled() { if engine.IsSearchEnabled() {
results, err := s.searchPostsInTeamForUserByEngine(engine, paramsList, userId, teamId, isOrSearch, includeDeletedChannels, page, perPage) results, err := s.searchPostsInTeamForUserByEngine(engine, paramsList, userId, teamId, page, perPage)
if err != nil { if err != nil {
mlog.Error("Encountered error on SearchPostsInTeamForUser.", mlog.String("search_engine", engine.GetName()), mlog.Err(err)) mlog.Error("Encountered error on SearchPostsInTeamForUser.", mlog.String("search_engine", engine.GetName()), mlog.Err(err))
continue continue
@@ -188,5 +192,5 @@ func (s SearchPostStore) SearchPostsInTeamForUser(paramsList []*model.SearchPara
} }
mlog.Debug("Using database search because no other search engine is available") mlog.Debug("Using database search because no other search engine is available")
return s.PostStore.SearchPostsInTeamForUser(paramsList, userId, teamId, isOrSearch, includeDeletedChannels, page, perPage) return s.PostStore.SearchPostsInTeamForUser(paramsList, userId, teamId, page, perPage)
} }

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

@@ -96,7 +96,7 @@ var searchPostStoreTests = []searchTest{
{ {
Name: "Should be able to search using boolean operators", Name: "Should be able to search using boolean operators",
Fn: testSearchUsingBooleanOperators, Fn: testSearchUsingBooleanOperators,
Tags: []string{ENGINE_ELASTICSEARCH}, Tags: []string{ENGINE_MYSQL, ENGINE_POSTGRES, ENGINE_ELASTICSEARCH},
}, },
{ {
Name: "Should be able to search with combined filters", Name: "Should be able to search with combined filters",
@@ -195,11 +195,9 @@ var searchPostStoreTests = []searchTest{
Tags: []string{ENGINE_ALL}, Tags: []string{ENGINE_ALL},
}, },
{ {
Name: "Should be able to search in deleted/archived channels", Name: "Should be able to search in deleted/archived channels",
Fn: testSearchInDeletedOrArchivedChannels, Fn: testSearchInDeletedOrArchivedChannels,
Tags: []string{ENGINE_ALL}, Tags: []string{ENGINE_MYSQL, ENGINE_POSTGRES},
Skip: true,
SkipMessage: "Not working",
}, },
{ {
Name: "Should be able to search terms with dashes", Name: "Should be able to search terms with dashes",
@@ -211,12 +209,12 @@ var searchPostStoreTests = []searchTest{
{ {
Name: "Should be able to search terms with dots", Name: "Should be able to search terms with dots",
Fn: testSearchTermsWithDots, Fn: testSearchTermsWithDots,
Tags: []string{ENGINE_ELASTICSEARCH}, Tags: []string{ENGINE_POSTGRES, ENGINE_ELASTICSEARCH},
}, },
{ {
Name: "Should be able to search terms with underscores", Name: "Should be able to search terms with underscores",
Fn: testSearchTermsWithUnderscores, Fn: testSearchTermsWithUnderscores,
Tags: []string{ENGINE_ELASTICSEARCH}, Tags: []string{ENGINE_MYSQL, ENGINE_ELASTICSEARCH},
}, },
{ {
Name: "Should be able to search posts made by bot accounts", Name: "Should be able to search posts made by bot accounts",
@@ -290,7 +288,7 @@ func testSearchPostsIncludingDMs(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id) defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "test"} params := &model.SearchParams{Terms: "test"}
results, err := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, err := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, err) require.Nil(t, err)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -312,13 +310,13 @@ func testSearchPostsWithPagination(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id) defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "test"} params := &model.SearchParams{Terms: "test"}
results, err := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 1) results, err := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 1)
require.Nil(t, err) require.Nil(t, err)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
th.checkPostInSearchResults(t, p2.Id, results.Posts) th.checkPostInSearchResults(t, p2.Id, results.Posts)
results, err = th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 1, 1) results, err = th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 1, 1)
require.Nil(t, err) require.Nil(t, err)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -333,7 +331,7 @@ func testSearchReturnPinnedAndUnpinned(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id) defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "test"} params := &model.SearchParams{Terms: "test"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -349,7 +347,7 @@ func testSearchExactPhraseInQuotes(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id) defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "\"channel test 1 2 3\""} params := &model.SearchParams{Terms: "\"channel test 1 2 3\""}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -365,7 +363,7 @@ func testSearchEmailAddresses(t *testing.T, th *SearchTestHelper) {
t.Run("Should search email addresses enclosed by quotes", func(t *testing.T) { t.Run("Should search email addresses enclosed by quotes", func(t *testing.T) {
params := &model.SearchParams{Terms: "\"test@test.com\""} params := &model.SearchParams{Terms: "\"test@test.com\""}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -374,7 +372,7 @@ func testSearchEmailAddresses(t *testing.T, th *SearchTestHelper) {
t.Run("Should search email addresses without quotes", func(t *testing.T) { t.Run("Should search email addresses without quotes", func(t *testing.T) {
params := &model.SearchParams{Terms: "test@test.com"} params := &model.SearchParams{Terms: "test@test.com"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -389,7 +387,7 @@ func testSearchMarkdownUnderscores(t *testing.T, th *SearchTestHelper) {
t.Run("Should search the start inside the markdown underscore", func(t *testing.T) { t.Run("Should search the start inside the markdown underscore", func(t *testing.T) {
params := &model.SearchParams{Terms: "start"} params := &model.SearchParams{Terms: "start"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -398,7 +396,7 @@ func testSearchMarkdownUnderscores(t *testing.T, th *SearchTestHelper) {
t.Run("Should search a word in the middle of the markdown underscore", func(t *testing.T) { t.Run("Should search a word in the middle of the markdown underscore", func(t *testing.T) {
params := &model.SearchParams{Terms: "middle"} params := &model.SearchParams{Terms: "middle"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -407,7 +405,7 @@ func testSearchMarkdownUnderscores(t *testing.T, th *SearchTestHelper) {
t.Run("Should search in the end of the markdown underscore", func(t *testing.T) { t.Run("Should search in the end of the markdown underscore", func(t *testing.T) {
params := &model.SearchParams{Terms: "end"} params := &model.SearchParams{Terms: "end"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -416,7 +414,7 @@ func testSearchMarkdownUnderscores(t *testing.T, th *SearchTestHelper) {
t.Run("Should search inside markdown underscore", func(t *testing.T) { t.Run("Should search inside markdown underscore", func(t *testing.T) {
params := &model.SearchParams{Terms: "another"} params := &model.SearchParams{Terms: "another"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -434,7 +432,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
t.Run("Should search one word", func(t *testing.T) { t.Run("Should search one word", func(t *testing.T) {
params := &model.SearchParams{Terms: "你"} params := &model.SearchParams{Terms: "你"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -442,7 +440,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
}) })
t.Run("Should search two words", func(t *testing.T) { t.Run("Should search two words", func(t *testing.T) {
params := &model.SearchParams{Terms: "你好"} params := &model.SearchParams{Terms: "你好"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -450,7 +448,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
}) })
t.Run("Should search with wildcard", func(t *testing.T) { t.Run("Should search with wildcard", func(t *testing.T) {
params := &model.SearchParams{Terms: "你*"} params := &model.SearchParams{Terms: "你*"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -465,7 +463,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
t.Run("Should search one word", func(t *testing.T) { t.Run("Should search one word", func(t *testing.T) {
params := &model.SearchParams{Terms: "слово"} params := &model.SearchParams{Terms: "слово"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -473,7 +471,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
}) })
t.Run("Should search using wildcard", func(t *testing.T) { t.Run("Should search using wildcard", func(t *testing.T) {
params := &model.SearchParams{Terms: "слов*"} params := &model.SearchParams{Terms: "слов*"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -490,7 +488,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
t.Run("Should search one word", func(t *testing.T) { t.Run("Should search one word", func(t *testing.T) {
params := &model.SearchParams{Terms: "本"} params := &model.SearchParams{Terms: "本"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -499,7 +497,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
}) })
t.Run("Should search two words", func(t *testing.T) { t.Run("Should search two words", func(t *testing.T) {
params := &model.SearchParams{Terms: "本木"} params := &model.SearchParams{Terms: "本木"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -507,7 +505,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
}) })
t.Run("Should search with wildcard", func(t *testing.T) { t.Run("Should search with wildcard", func(t *testing.T) {
params := &model.SearchParams{Terms: "本*"} params := &model.SearchParams{Terms: "本*"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -525,7 +523,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
t.Run("Should search one word", func(t *testing.T) { t.Run("Should search one word", func(t *testing.T) {
params := &model.SearchParams{Terms: "불"} params := &model.SearchParams{Terms: "불"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -533,7 +531,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
}) })
t.Run("Should search two words", func(t *testing.T) { t.Run("Should search two words", func(t *testing.T) {
params := &model.SearchParams{Terms: "불다"} params := &model.SearchParams{Terms: "불다"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -541,7 +539,7 @@ func testSearchNonLatinWords(t *testing.T, th *SearchTestHelper) {
}) })
t.Run("Should search with wildcard", func(t *testing.T) { t.Run("Should search with wildcard", func(t *testing.T) {
params := &model.SearchParams{Terms: "불*"} params := &model.SearchParams{Terms: "불*"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -559,7 +557,7 @@ func testSearchAlternativeSpellings(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id) defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "Straße"} params := &model.SearchParams{Terms: "Straße"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -567,7 +565,7 @@ func testSearchAlternativeSpellings(t *testing.T, th *SearchTestHelper) {
th.checkPostInSearchResults(t, p2.Id, results.Posts) th.checkPostInSearchResults(t, p2.Id, results.Posts)
params = &model.SearchParams{Terms: "Strasse"} params = &model.SearchParams{Terms: "Strasse"}
results, apperr = th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr = th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -583,7 +581,7 @@ func testSearchAlternativeSpellingsAccents(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id) defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "café"} params := &model.SearchParams{Terms: "café"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -591,7 +589,7 @@ func testSearchAlternativeSpellingsAccents(t *testing.T, th *SearchTestHelper) {
th.checkPostInSearchResults(t, p2.Id, results.Posts) th.checkPostInSearchResults(t, p2.Id, results.Posts)
params = &model.SearchParams{Terms: "café"} params = &model.SearchParams{Terms: "café"}
results, apperr = th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr = th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -599,7 +597,7 @@ func testSearchAlternativeSpellingsAccents(t *testing.T, th *SearchTestHelper) {
th.checkPostInSearchResults(t, p2.Id, results.Posts) th.checkPostInSearchResults(t, p2.Id, results.Posts)
params = &model.SearchParams{Terms: "cafe"} params = &model.SearchParams{Terms: "cafe"}
results, apperr = th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr = th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 0) require.Len(t, results.Posts, 0)
@@ -617,7 +615,7 @@ func testSearchOrExcludePostsBySpecificUser(t *testing.T, th *SearchTestHelper)
Terms: "fromuser", Terms: "fromuser",
FromUsers: []string{th.User.Id}, FromUsers: []string{th.User.Id},
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -636,7 +634,7 @@ func testSearchOrExcludePostsInChannel(t *testing.T, th *SearchTestHelper) {
Terms: "fromuser", Terms: "fromuser",
InChannels: []string{th.ChannelBasic.Id}, InChannels: []string{th.ChannelBasic.Id},
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -664,7 +662,7 @@ func testSearchOrExcludePostsInDMGM(t *testing.T, th *SearchTestHelper) {
Terms: "fromuser", Terms: "fromuser",
InChannels: []string{direct.Id, group.Id}, InChannels: []string{direct.Id, group.Id},
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -677,7 +675,7 @@ func testSearchOrExcludePostsInDMGM(t *testing.T, th *SearchTestHelper) {
Terms: "fromuser", Terms: "fromuser",
InChannels: []string{direct.Id}, InChannels: []string{direct.Id},
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -689,7 +687,7 @@ func testSearchOrExcludePostsInDMGM(t *testing.T, th *SearchTestHelper) {
Terms: "fromuser", Terms: "fromuser",
InChannels: []string{group.Id}, InChannels: []string{group.Id},
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -714,7 +712,7 @@ func testFilterMessagesInSpecificDate(t *testing.T, th *SearchTestHelper) {
Terms: "test", Terms: "test",
OnDate: "2020-03-22", OnDate: "2020-03-22",
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -725,7 +723,7 @@ func testFilterMessagesInSpecificDate(t *testing.T, th *SearchTestHelper) {
Terms: "test", Terms: "test",
ExcludedDate: "2020-03-22", ExcludedDate: "2020-03-22",
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -751,7 +749,7 @@ func testFilterMessagesBeforeSpecificDate(t *testing.T, th *SearchTestHelper) {
Terms: "test", Terms: "test",
BeforeDate: "2020-03-23", BeforeDate: "2020-03-23",
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -764,7 +762,7 @@ func testFilterMessagesBeforeSpecificDate(t *testing.T, th *SearchTestHelper) {
Terms: "test", Terms: "test",
ExcludedBeforeDate: "2020-03-23", ExcludedBeforeDate: "2020-03-23",
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -789,7 +787,7 @@ func testFilterMessagesAfterSpecificDate(t *testing.T, th *SearchTestHelper) {
Terms: "test", Terms: "test",
AfterDate: "2020-03-23", AfterDate: "2020-03-23",
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -801,7 +799,7 @@ func testFilterMessagesAfterSpecificDate(t *testing.T, th *SearchTestHelper) {
Terms: "test", Terms: "test",
ExcludedAfterDate: "2020-03-23", ExcludedAfterDate: "2020-03-23",
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -824,7 +822,7 @@ func testFilterMessagesWithATerm(t *testing.T, th *SearchTestHelper) {
Terms: "one", Terms: "one",
ExcludedTerms: "five eight", ExcludedTerms: "five eight",
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -836,7 +834,7 @@ func testFilterMessagesWithATerm(t *testing.T, th *SearchTestHelper) {
Terms: "one", Terms: "one",
ExcludedTerms: "\"eight nine\"", ExcludedTerms: "\"eight nine\"",
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -859,7 +857,7 @@ func testSearchUsingBooleanOperators(t *testing.T, th *SearchTestHelper) {
Terms: "one two", Terms: "one two",
OrTerms: true, OrTerms: true,
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -872,7 +870,7 @@ func testSearchUsingBooleanOperators(t *testing.T, th *SearchTestHelper) {
Terms: "one two", Terms: "one two",
OrTerms: false, OrTerms: false,
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -899,7 +897,7 @@ func testSearchUsingCombinedFilters(t *testing.T, th *SearchTestHelper) {
FromUsers: []string{th.User2.Id}, FromUsers: []string{th.User2.Id},
InChannels: []string{th.ChannelPrivate.Id}, InChannels: []string{th.ChannelPrivate.Id},
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -912,7 +910,7 @@ func testSearchUsingCombinedFilters(t *testing.T, th *SearchTestHelper) {
ExcludedUsers: []string{th.User2.Id}, ExcludedUsers: []string{th.User2.Id},
InChannels: []string{th.ChannelPrivate.Id}, InChannels: []string{th.ChannelPrivate.Id},
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -926,7 +924,7 @@ func testSearchUsingCombinedFilters(t *testing.T, th *SearchTestHelper) {
ExcludedAfterDate: "2020-03-11", ExcludedAfterDate: "2020-03-11",
InChannels: []string{th.ChannelPrivate.Id}, InChannels: []string{th.ChannelPrivate.Id},
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -938,7 +936,7 @@ func testSearchUsingCombinedFilters(t *testing.T, th *SearchTestHelper) {
AfterDate: "2020-03-11", AfterDate: "2020-03-11",
ExcludedChannels: []string{th.ChannelPrivate.Id}, ExcludedChannels: []string{th.ChannelPrivate.Id},
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -961,7 +959,7 @@ func testSearchIgnoringStopWords(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{ params := &model.SearchParams{
Terms: "the search", Terms: "the search",
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -972,7 +970,7 @@ func testSearchIgnoringStopWords(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{ params := &model.SearchParams{
Terms: "a avoid", Terms: "a avoid",
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -983,7 +981,7 @@ func testSearchIgnoringStopWords(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{ params := &model.SearchParams{
Terms: "in where you", Terms: "in where you",
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1016,7 +1014,7 @@ func testSupportStemming(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{ params := &model.SearchParams{
Terms: "search", Terms: "search",
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -1036,7 +1034,7 @@ func testSupportWildcards(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{ params := &model.SearchParams{
Terms: "search*", Terms: "search*",
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -1056,7 +1054,7 @@ func testNotSupportPrecedingWildcards(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{ params := &model.SearchParams{
Terms: "*earch", Terms: "*earch",
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 0) require.Len(t, results.Posts, 0)
@@ -1072,7 +1070,7 @@ func testSearchDiscardWildcardAlone(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{ params := &model.SearchParams{
Terms: "qwerty *", Terms: "qwerty *",
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1090,7 +1088,7 @@ func testSupportTermsWithDash(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{ params := &model.SearchParams{
Terms: "term-with-dash", Terms: "term-with-dash",
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1101,7 +1099,7 @@ func testSupportTermsWithDash(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{ params := &model.SearchParams{
Terms: "\"term-with-dash\"", Terms: "\"term-with-dash\"",
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1120,7 +1118,7 @@ func testSupportTermsWithUnderscore(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{ params := &model.SearchParams{
Terms: "term_with_underscore", Terms: "term_with_underscore",
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1131,7 +1129,7 @@ func testSupportTermsWithUnderscore(t *testing.T, th *SearchTestHelper) {
params := &model.SearchParams{ params := &model.SearchParams{
Terms: "\"term_with_underscore\"", Terms: "\"term_with_underscore\"",
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1153,7 +1151,7 @@ func testSearchOrExcludePostsWithHashtags(t *testing.T, th *SearchTestHelper) {
Terms: "#hashtag", Terms: "#hashtag",
IsHashtag: true, IsHashtag: true,
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -1166,7 +1164,7 @@ func testSearchOrExcludePostsWithHashtags(t *testing.T, th *SearchTestHelper) {
Terms: "#hashtag", Terms: "#hashtag",
IsHashtag: false, IsHashtag: false,
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -1192,7 +1190,7 @@ func testSearchHashtagWithMarkdown(t *testing.T, th *SearchTestHelper) {
Terms: "#hashtag", Terms: "#hashtag",
IsHashtag: true, IsHashtag: true,
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 5) require.Len(t, results.Posts, 5)
@@ -1215,7 +1213,7 @@ func testSearcWithMultipleHashtags(t *testing.T, th *SearchTestHelper) {
Terms: "#hashone #hashtwo", Terms: "#hashone #hashtwo",
IsHashtag: true, IsHashtag: true,
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1228,7 +1226,7 @@ func testSearcWithMultipleHashtags(t *testing.T, th *SearchTestHelper) {
IsHashtag: true, IsHashtag: true,
OrTerms: true, OrTerms: true,
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -1246,7 +1244,7 @@ func testSearchPostsWithDotsInHashtags(t *testing.T, th *SearchTestHelper) {
Terms: "#hashtag.dot", Terms: "#hashtag.dot",
IsHashtag: true, IsHashtag: true,
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1267,7 +1265,7 @@ func testSearchHashtagCaseInsensitive(t *testing.T, th *SearchTestHelper) {
Terms: "#hashtag", Terms: "#hashtag",
IsHashtag: true, IsHashtag: true,
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 3) require.Len(t, results.Posts, 3)
@@ -1281,7 +1279,7 @@ func testSearchHashtagCaseInsensitive(t *testing.T, th *SearchTestHelper) {
Terms: "#HASHTAG", Terms: "#HASHTAG",
IsHashtag: true, IsHashtag: true,
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 3) require.Len(t, results.Posts, 3)
@@ -1295,7 +1293,7 @@ func testSearchHashtagCaseInsensitive(t *testing.T, th *SearchTestHelper) {
Terms: "#HaShTaG", Terms: "#HaShTaG",
IsHashtag: true, IsHashtag: true,
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 3) require.Len(t, results.Posts, 3)
@@ -1316,7 +1314,7 @@ func testSearchHashtagWithDash(t *testing.T, th *SearchTestHelper) {
Terms: "#hashtag-test", Terms: "#hashtag-test",
IsHashtag: true, IsHashtag: true,
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1334,7 +1332,7 @@ func testSearchHashtagWithNumbers(t *testing.T, th *SearchTestHelper) {
Terms: "#h4sht4g", Terms: "#h4sht4g",
IsHashtag: true, IsHashtag: true,
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1352,7 +1350,7 @@ func testSearchHashtagWithDots(t *testing.T, th *SearchTestHelper) {
Terms: "#hashtag.test", Terms: "#hashtag.test",
IsHashtag: true, IsHashtag: true,
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1370,7 +1368,7 @@ func testSearchHashtagWithUnderscores(t *testing.T, th *SearchTestHelper) {
Terms: "#hashtag_test", Terms: "#hashtag_test",
IsHashtag: true, IsHashtag: true,
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1393,7 +1391,7 @@ func testSearchShouldExcludeSytemMessages(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id) defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "test system"} params := &model.SearchParams{Terms: "test system"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 0) require.Len(t, results.Posts, 0)
@@ -1409,7 +1407,7 @@ func testSearchShouldBeAbleToMatchByMentions(t *testing.T, th *SearchTestHelper)
defer th.deleteUserPosts(th.User.Id) defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "@testuser"} params := &model.SearchParams{Terms: "@testuser"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 3) require.Len(t, results.Posts, 3)
@@ -1429,7 +1427,7 @@ func testSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestHelper) {
t.Run("Doesn't include posts in deleted channels", func(t *testing.T) { t.Run("Doesn't include posts in deleted channels", func(t *testing.T) {
params := &model.SearchParams{Terms: "message", IncludeDeletedChannels: false} params := &model.SearchParams{Terms: "message", IncludeDeletedChannels: false}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -1439,7 +1437,7 @@ func testSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestHelper) {
t.Run("Include posts in deleted channels", func(t *testing.T) { t.Run("Include posts in deleted channels", func(t *testing.T) {
params := &model.SearchParams{Terms: "message", IncludeDeletedChannels: true} params := &model.SearchParams{Terms: "message", IncludeDeletedChannels: true}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 3) require.Len(t, results.Posts, 3)
@@ -1450,7 +1448,7 @@ func testSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestHelper) {
t.Run("Include posts in deleted channels using multiple terms", func(t *testing.T) { t.Run("Include posts in deleted channels using multiple terms", func(t *testing.T) {
params := &model.SearchParams{Terms: "message channel", IncludeDeletedChannels: true} params := &model.SearchParams{Terms: "message channel", IncludeDeletedChannels: true}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 3) require.Len(t, results.Posts, 3)
@@ -1465,7 +1463,7 @@ func testSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestHelper) {
IncludeDeletedChannels: true, IncludeDeletedChannels: true,
OrTerms: true, OrTerms: true,
} }
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 3) require.Len(t, results.Posts, 3)
@@ -1473,6 +1471,20 @@ func testSearchInDeletedOrArchivedChannels(t *testing.T, th *SearchTestHelper) {
th.checkPostInSearchResults(t, p2.Id, results.Posts) th.checkPostInSearchResults(t, p2.Id, results.Posts)
th.checkPostInSearchResults(t, p3.Id, results.Posts) th.checkPostInSearchResults(t, p3.Id, results.Posts)
}) })
t.Run("All IncludeDeletedChannels params should have same value if multiple SearchParams provided", func(t *testing.T) {
params1 := &model.SearchParams{
Terms: "message channel",
IncludeDeletedChannels: true,
}
params2 := &model.SearchParams{
Terms: "#hashtag",
IncludeDeletedChannels: false,
}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params1, params2}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, results)
require.NotNil(t, apperr)
})
} }
func testSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) { func testSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
@@ -1484,7 +1496,7 @@ func testSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
t.Run("Search for terms with dash", func(t *testing.T) { t.Run("Search for terms with dash", func(t *testing.T) {
params := &model.SearchParams{Terms: "with-dash-term"} params := &model.SearchParams{Terms: "with-dash-term"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1493,7 +1505,7 @@ func testSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
t.Run("Search for terms with quoted dash", func(t *testing.T) { t.Run("Search for terms with quoted dash", func(t *testing.T) {
params := &model.SearchParams{Terms: "\"with-dash-term\""} params := &model.SearchParams{Terms: "\"with-dash-term\""}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1502,7 +1514,7 @@ func testSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
t.Run("Search for multiple terms with one having dash", func(t *testing.T) { t.Run("Search for multiple terms with one having dash", func(t *testing.T) {
params := &model.SearchParams{Terms: "with-dash-term message"} params := &model.SearchParams{Terms: "with-dash-term message"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1511,7 +1523,7 @@ func testSearchTermsWithDashes(t *testing.T, th *SearchTestHelper) {
t.Run("Search for multiple OR terms with one having dash", func(t *testing.T) { t.Run("Search for multiple OR terms with one having dash", func(t *testing.T) {
params := &model.SearchParams{Terms: "with-dash-term message", OrTerms: true} params := &model.SearchParams{Terms: "with-dash-term message", OrTerms: true}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -1529,7 +1541,7 @@ func testSearchTermsWithDots(t *testing.T, th *SearchTestHelper) {
t.Run("Search for terms with dots", func(t *testing.T) { t.Run("Search for terms with dots", func(t *testing.T) {
params := &model.SearchParams{Terms: "with.dots.term"} params := &model.SearchParams{Terms: "with.dots.term"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1538,7 +1550,7 @@ func testSearchTermsWithDots(t *testing.T, th *SearchTestHelper) {
t.Run("Search for terms with quoted dots", func(t *testing.T) { t.Run("Search for terms with quoted dots", func(t *testing.T) {
params := &model.SearchParams{Terms: "\"with.dots.term\""} params := &model.SearchParams{Terms: "\"with.dots.term\""}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1547,7 +1559,7 @@ func testSearchTermsWithDots(t *testing.T, th *SearchTestHelper) {
t.Run("Search for multiple terms with one having dots", func(t *testing.T) { t.Run("Search for multiple terms with one having dots", func(t *testing.T) {
params := &model.SearchParams{Terms: "with.dots.term message"} params := &model.SearchParams{Terms: "with.dots.term message"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1556,7 +1568,7 @@ func testSearchTermsWithDots(t *testing.T, th *SearchTestHelper) {
t.Run("Search for multiple OR terms with one having dots", func(t *testing.T) { t.Run("Search for multiple OR terms with one having dots", func(t *testing.T) {
params := &model.SearchParams{Terms: "with.dots.term message", OrTerms: true} params := &model.SearchParams{Terms: "with.dots.term message", OrTerms: true}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -1574,7 +1586,7 @@ func testSearchTermsWithUnderscores(t *testing.T, th *SearchTestHelper) {
t.Run("Search for terms with underscores", func(t *testing.T) { t.Run("Search for terms with underscores", func(t *testing.T) {
params := &model.SearchParams{Terms: "with_underscores_term"} params := &model.SearchParams{Terms: "with_underscores_term"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1583,7 +1595,7 @@ func testSearchTermsWithUnderscores(t *testing.T, th *SearchTestHelper) {
t.Run("Search for terms with quoted underscores", func(t *testing.T) { t.Run("Search for terms with quoted underscores", func(t *testing.T) {
params := &model.SearchParams{Terms: "\"with_underscores_term\""} params := &model.SearchParams{Terms: "\"with_underscores_term\""}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1592,7 +1604,7 @@ func testSearchTermsWithUnderscores(t *testing.T, th *SearchTestHelper) {
t.Run("Search for multiple terms with one having underscores", func(t *testing.T) { t.Run("Search for multiple terms with one having underscores", func(t *testing.T) {
params := &model.SearchParams{Terms: "with_underscores_term message"} params := &model.SearchParams{Terms: "with_underscores_term message"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1601,7 +1613,7 @@ func testSearchTermsWithUnderscores(t *testing.T, th *SearchTestHelper) {
t.Run("Search for multiple OR terms with one having underscores", func(t *testing.T) { t.Run("Search for multiple OR terms with one having underscores", func(t *testing.T) {
params := &model.SearchParams{Terms: "with_underscores_term message", OrTerms: true} params := &model.SearchParams{Terms: "with_underscores_term message", OrTerms: true}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -1623,7 +1635,7 @@ func testSearchBotAccountsPosts(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(bot.UserId) defer th.deleteUserPosts(bot.UserId)
params := &model.SearchParams{Terms: "bot"} params := &model.SearchParams{Terms: "bot"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -1642,7 +1654,7 @@ func testSupportStemmingAndWildcards(t *testing.T, th *SearchTestHelper) {
t.Run("Should stem appr", func(t *testing.T) { t.Run("Should stem appr", func(t *testing.T) {
params := &model.SearchParams{Terms: "appr*"} params := &model.SearchParams{Terms: "appr*"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 3) require.Len(t, results.Posts, 3)
@@ -1653,7 +1665,7 @@ func testSupportStemmingAndWildcards(t *testing.T, th *SearchTestHelper) {
t.Run("Should stem approve", func(t *testing.T) { t.Run("Should stem approve", func(t *testing.T) {
params := &model.SearchParams{Terms: "approve*"} params := &model.SearchParams{Terms: "approve*"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1670,7 +1682,7 @@ func testSupportWildcardOutsideQuotes(t *testing.T, th *SearchTestHelper) {
t.Run("Should return results without quotes", func(t *testing.T) { t.Run("Should return results without quotes", func(t *testing.T) {
params := &model.SearchParams{Terms: "hell*"} params := &model.SearchParams{Terms: "hell*"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 2) require.Len(t, results.Posts, 2)
@@ -1680,7 +1692,7 @@ func testSupportWildcardOutsideQuotes(t *testing.T, th *SearchTestHelper) {
t.Run("Should return just one result with quotes", func(t *testing.T) { t.Run("Should return just one result with quotes", func(t *testing.T) {
params := &model.SearchParams{Terms: "\"hell\"*"} params := &model.SearchParams{Terms: "\"hell\"*"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1699,7 +1711,7 @@ func testHashtagSearchShouldSupportThreeOrMoreCharacters(t *testing.T, th *Searc
defer th.deleteUserPosts(th.User.Id) defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "#123", IsHashtag: true} params := &model.SearchParams{Terms: "#123", IsHashtag: true}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1712,21 +1724,21 @@ func testSlashShouldNotBeCharSeparator(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id) defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "gamma"} params := &model.SearchParams{Terms: "gamma"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
th.checkPostInSearchResults(t, p1.Id, results.Posts) th.checkPostInSearchResults(t, p1.Id, results.Posts)
params = &model.SearchParams{Terms: "beta"} params = &model.SearchParams{Terms: "beta"}
results, apperr = th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr = th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
th.checkPostInSearchResults(t, p1.Id, results.Posts) th.checkPostInSearchResults(t, p1.Id, results.Posts)
params = &model.SearchParams{Terms: "alpha"} params = &model.SearchParams{Terms: "alpha"}
results, apperr = th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr = th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1741,7 +1753,7 @@ func testSearchEmailsWithoutQuotes(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id) defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "test@test.com"} params := &model.SearchParams{Terms: "test@test.com"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1756,7 +1768,7 @@ func testSupportSearchInComments(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id) defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "reply"} params := &model.SearchParams{Terms: "reply"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1769,7 +1781,7 @@ func testSupportSearchTermsWithinLinks(t *testing.T, th *SearchTestHelper) {
defer th.deleteUserPosts(th.User.Id) defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "wikipedia"} params := &model.SearchParams{Terms: "wikipedia"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 1) require.Len(t, results.Posts, 1)
@@ -1782,7 +1794,7 @@ func testShouldNotReturnLinksEmbeddedInMarkdown(t *testing.T, th *SearchTestHelp
defer th.deleteUserPosts(th.User.Id) defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{Terms: "wikipedia"} params := &model.SearchParams{Terms: "wikipedia"}
results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, false, false, 0, 20) results, apperr := th.Store.Post().SearchPostsInTeamForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.Nil(t, apperr) require.Nil(t, apperr)
require.Len(t, results.Posts, 0) require.Len(t, results.Posts, 0)

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

@@ -1804,12 +1804,16 @@ func (s *SqlPostStore) GetDirectPostParentsForExportAfter(limit int, afterId str
return posts, nil return posts, nil
} }
func (s *SqlPostStore) SearchPostsInTeamForUser(paramsList []*model.SearchParams, userId, teamId string, isOrSearch, includeDeletedChannels bool, page, perPage int) (*model.PostSearchResults, *model.AppError) { func (s *SqlPostStore) SearchPostsInTeamForUser(paramsList []*model.SearchParams, userId, teamId string, page, perPage int) (*model.PostSearchResults, *model.AppError) {
// Since we don't support paging for DB search, we just return nothing for later pages // Since we don't support paging for DB search, we just return nothing for later pages
if page > 0 { if page > 0 {
return model.MakePostSearchResults(model.NewPostList(), nil), nil return model.MakePostSearchResults(model.NewPostList(), nil), nil
} }
if err := model.IsSearchParamsListValid(paramsList); err != nil {
return nil, err
}
var wg sync.WaitGroup var wg sync.WaitGroup
pchan := make(chan store.StoreResult, len(paramsList)) pchan := make(chan store.StoreResult, len(paramsList))
@@ -1818,8 +1822,6 @@ func (s *SqlPostStore) SearchPostsInTeamForUser(paramsList []*model.SearchParams
// remove any unquoted term that contains only non-alphanumeric chars // remove any unquoted term that contains only non-alphanumeric chars
// ex: abcd "**" && abc >> abcd "**" abc // ex: abcd "**" && abc >> abcd "**" abc
params.Terms = removeNonAlphaNumericUnquotedTerms(params.Terms, " ") params.Terms = removeNonAlphaNumericUnquotedTerms(params.Terms, " ")
params.IncludeDeletedChannels = includeDeletedChannels
params.OrTerms = isOrSearch
wg.Add(1) wg.Add(1)

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

@@ -282,7 +282,7 @@ type PostStore interface {
GetParentsForExportAfter(limit int, afterId string) ([]*model.PostForExport, *model.AppError) GetParentsForExportAfter(limit int, afterId string) ([]*model.PostForExport, *model.AppError)
GetRepliesForExport(parentId string) ([]*model.ReplyForExport, *model.AppError) GetRepliesForExport(parentId string) ([]*model.ReplyForExport, *model.AppError)
GetDirectPostParentsForExportAfter(limit int, afterId string) ([]*model.DirectPostForExport, *model.AppError) GetDirectPostParentsForExportAfter(limit int, afterId string) ([]*model.DirectPostForExport, *model.AppError)
SearchPostsInTeamForUser(paramsList []*model.SearchParams, userId, teamId string, isOrSearch, includeDeletedChannels bool, page, perPage int) (*model.PostSearchResults, *model.AppError) SearchPostsInTeamForUser(paramsList []*model.SearchParams, userId, teamId string, page, perPage int) (*model.PostSearchResults, *model.AppError)
GetOldestEntityCreationTime() (int64, *model.AppError) GetOldestEntityCreationTime() (int64, *model.AppError)
} }

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

@@ -815,13 +815,13 @@ func (_m *PostStore) Search(teamId string, userId string, params *model.SearchPa
return r0, r1 return r0, r1
} }
// SearchPostsInTeamForUser provides a mock function with given fields: paramsList, userId, teamId, isOrSearch, includeDeletedChannels, page, perPage // SearchPostsInTeamForUser provides a mock function with given fields: paramsList, userId, teamId, page, perPage
func (_m *PostStore) SearchPostsInTeamForUser(paramsList []*model.SearchParams, userId string, teamId string, isOrSearch bool, includeDeletedChannels bool, page int, perPage int) (*model.PostSearchResults, *model.AppError) { func (_m *PostStore) SearchPostsInTeamForUser(paramsList []*model.SearchParams, userId string, teamId string, page int, perPage int) (*model.PostSearchResults, *model.AppError) {
ret := _m.Called(paramsList, userId, teamId, isOrSearch, includeDeletedChannels, page, perPage) ret := _m.Called(paramsList, userId, teamId, page, perPage)
var r0 *model.PostSearchResults var r0 *model.PostSearchResults
if rf, ok := ret.Get(0).(func([]*model.SearchParams, string, string, bool, bool, int, int) *model.PostSearchResults); ok { if rf, ok := ret.Get(0).(func([]*model.SearchParams, string, string, int, int) *model.PostSearchResults); ok {
r0 = rf(paramsList, userId, teamId, isOrSearch, includeDeletedChannels, page, perPage) r0 = rf(paramsList, userId, teamId, page, perPage)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.PostSearchResults) r0 = ret.Get(0).(*model.PostSearchResults)
@@ -829,8 +829,8 @@ func (_m *PostStore) SearchPostsInTeamForUser(paramsList []*model.SearchParams,
} }
var r1 *model.AppError var r1 *model.AppError
if rf, ok := ret.Get(1).(func([]*model.SearchParams, string, string, bool, bool, int, int) *model.AppError); ok { if rf, ok := ret.Get(1).(func([]*model.SearchParams, string, string, int, int) *model.AppError); ok {
r1 = rf(paramsList, userId, teamId, isOrSearch, includeDeletedChannels, page, perPage) r1 = rf(paramsList, userId, teamId, page, perPage)
} else { } else {
if ret.Get(1) != nil { if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError) r1 = ret.Get(1).(*model.AppError)

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

@@ -4829,10 +4829,10 @@ func (s *TimerLayerPostStore) Search(teamId string, userId string, params *model
return result, err return result, err
} }
func (s *TimerLayerPostStore) SearchPostsInTeamForUser(paramsList []*model.SearchParams, userId string, teamId string, isOrSearch bool, includeDeletedChannels bool, page int, perPage int) (*model.PostSearchResults, *model.AppError) { func (s *TimerLayerPostStore) SearchPostsInTeamForUser(paramsList []*model.SearchParams, userId string, teamId string, page int, perPage int) (*model.PostSearchResults, *model.AppError) {
start := timemodule.Now() start := timemodule.Now()
result, err := s.PostStore.SearchPostsInTeamForUser(paramsList, userId, teamId, isOrSearch, includeDeletedChannels, page, perPage) result, err := s.PostStore.SearchPostsInTeamForUser(paramsList, userId, teamId, page, perPage)
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second) elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
if s.Root.Metrics != nil { if s.Root.Metrics != nil {