Fixed hashtag search for DB search (#23313)

* Fixed hashtag search for DB search

* Fixed typo

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Harshil Sharma
2023-05-17 12:01:31 +05:30
коммит произвёл GitHub
родитель 02be384baf
Коммит da3dcf737c
2 изменённых файлов: 42 добавлений и 2 удалений

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

@@ -192,6 +192,11 @@ var searchPostStoreTests = []searchTest{
Fn: testSearchHashtagWithUnderscores,
Tags: []string{EngineAll},
},
{
Name: "Should be able to search by hashtags with dashes and numbers",
Fn: testSearchHashtagWithDashAndNumbers,
Tags: []string{EngineAll},
},
{
Name: "Should not return system messages",
Fn: testSearchShouldExcludeSystemMessages,
@@ -1416,6 +1421,29 @@ func testSearchHashtagWithUnderscores(t *testing.T, th *SearchTestHelper) {
th.checkPostInSearchResults(t, p1.Id, results.Posts)
}
func testSearchHashtagWithDashAndNumbers(t *testing.T, th *SearchTestHelper) {
p1, err := th.createPost(th.User.Id, th.ChannelBasic.Id, "searching hashtag #hashtag-1-finals23", "#hashtag-1-finals23", model.PostTypeDefault, 0, false)
require.NoError(t, err)
p2, err := th.createPost(th.User.Id, th.ChannelBasic.Id, "searching hashtag #hashtag-1-finals23", "#hashtag-1-finals23", model.PostTypeDefault, 0, false)
require.NoError(t, err)
_, err = th.createPost(th.User.Id, th.ChannelBasic.Id, "searching hashtag #hashtag-finals20", "#hashtag-finals20", model.PostTypeDefault, 0, false)
require.NoError(t, err)
defer th.deleteUserPosts(th.User.Id)
params := &model.SearchParams{
Terms: "#hashtag-1-finals23",
IsHashtag: true,
}
results, err := th.Store.Post().SearchPostsForUser([]*model.SearchParams{params}, th.User.Id, th.Team.Id, 0, 20)
require.NoError(t, err)
require.Len(t, results.Posts, 2)
th.checkPostInSearchResults(t, p1.Id, results.Posts)
th.checkPostInSearchResults(t, p2.Id, results.Posts)
}
func testSearchShouldExcludeSystemMessages(t *testing.T, th *SearchTestHelper) {
_, err := th.createPost(th.User.Id, th.ChannelBasic.Id, "test system message one", "", model.PostTypeJoinChannel, 0, false)
require.NoError(t, err)