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 удалений

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

@@ -1982,7 +1982,9 @@ func (s *SqlPostStore) search(teamId string, userId string, params *model.Search
}
for _, c := range s.specialSearchChars() {
terms = strings.Replace(terms, c, " ", -1)
if !params.IsHashtag {
terms = strings.Replace(terms, c, " ", -1)
}
excludedTerms = strings.Replace(excludedTerms, c, " ", -1)
}
@@ -2007,7 +2009,12 @@ func (s *SqlPostStore) search(teamId string, userId string, params *model.Search
} else if strings.HasPrefix(terms, `"`) && strings.HasSuffix(terms, `"`) {
termsClause = "(" + strings.Join(strings.Fields(terms), " <-> ") + ")" + excludeClause
} else {
termsClause = "(" + strings.Join(strings.Fields(terms), " & ") + ")" + excludeClause
tsVectorSearchQuery := strings.Join(strings.Fields(terms), " & ")
if params.IsHashtag {
tsVectorSearchQuery = terms
}
termsClause = "(" + tsVectorSearchQuery + ")" + excludeClause
}
searchClause := fmt.Sprintf("to_tsvector('%[1]s', %[2]s) @@ to_tsquery('%[1]s', ?)", s.pgDefaultTextSearchConfig, searchType)
@@ -2041,6 +2048,11 @@ func (s *SqlPostStore) search(teamId string, userId string, params *model.Search
}
searchClause := fmt.Sprintf("MATCH (%s) AGAINST (? IN BOOLEAN MODE)", searchType)
if params.IsHashtag {
termsClause = "\"" + termsClause + "\""
}
baseQuery = baseQuery.Where(searchClause, termsClause)
}