Add search engine support for files (#16190)
* Add search engine support for files * Fixing i18n * Fix golangci-lint * Fix consistency problem in the Search receiver functio of the SqlFileStore * Fixing some tests * Fixing test * Apply suggestions from code review Co-authored-by: Mario de Frutos Dieguez <mario@defrutos.org> * Addressing PR review comments * Removing some empty lines * Address PR review comments * Fixing problem after merge master * Fixing spelling problem * Add missed translations * Fixing certain global variable usages after merge master * Fixing some constants usage * Fixing goimports order Co-authored-by: Mario de Frutos Dieguez <mario@defrutos.org>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
bcacc78f77
Коммит
2a63b5552a
128
model/file_info_list.go
Обычный файл
128
model/file_info_list.go
Обычный файл
@@ -0,0 +1,128 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type FileInfoList struct {
|
||||
Order []string `json:"order"`
|
||||
FileInfos map[string]*FileInfo `json:"file_infos"`
|
||||
NextFileInfoId string `json:"next_file_info_id"`
|
||||
PrevFileInfoId string `json:"prev_file_info_id"`
|
||||
}
|
||||
|
||||
func NewFileInfoList() *FileInfoList {
|
||||
return &FileInfoList{
|
||||
Order: make([]string, 0),
|
||||
FileInfos: make(map[string]*FileInfo),
|
||||
NextFileInfoId: "",
|
||||
PrevFileInfoId: "",
|
||||
}
|
||||
}
|
||||
|
||||
func (o *FileInfoList) ToSlice() []*FileInfo {
|
||||
var fileInfos []*FileInfo
|
||||
for _, id := range o.Order {
|
||||
fileInfos = append(fileInfos, o.FileInfos[id])
|
||||
}
|
||||
return fileInfos
|
||||
}
|
||||
|
||||
func (o *FileInfoList) ToJson() string {
|
||||
b, err := json.Marshal(o)
|
||||
if err != nil {
|
||||
return ""
|
||||
} else {
|
||||
return string(b)
|
||||
}
|
||||
}
|
||||
|
||||
func (o *FileInfoList) MakeNonNil() {
|
||||
if o.Order == nil {
|
||||
o.Order = make([]string, 0)
|
||||
}
|
||||
|
||||
if o.FileInfos == nil {
|
||||
o.FileInfos = make(map[string]*FileInfo)
|
||||
}
|
||||
}
|
||||
|
||||
func (o *FileInfoList) AddOrder(id string) {
|
||||
if o.Order == nil {
|
||||
o.Order = make([]string, 0, 128)
|
||||
}
|
||||
|
||||
o.Order = append(o.Order, id)
|
||||
}
|
||||
|
||||
func (o *FileInfoList) AddFileInfo(fileInfo *FileInfo) {
|
||||
if o.FileInfos == nil {
|
||||
o.FileInfos = make(map[string]*FileInfo)
|
||||
}
|
||||
|
||||
o.FileInfos[fileInfo.Id] = fileInfo
|
||||
}
|
||||
|
||||
func (o *FileInfoList) UniqueOrder() {
|
||||
keys := make(map[string]bool)
|
||||
order := []string{}
|
||||
for _, fileInfoId := range o.Order {
|
||||
if _, value := keys[fileInfoId]; !value {
|
||||
keys[fileInfoId] = true
|
||||
order = append(order, fileInfoId)
|
||||
}
|
||||
}
|
||||
|
||||
o.Order = order
|
||||
}
|
||||
|
||||
func (o *FileInfoList) Extend(other *FileInfoList) {
|
||||
for fileInfoId := range other.FileInfos {
|
||||
o.AddFileInfo(other.FileInfos[fileInfoId])
|
||||
}
|
||||
|
||||
for _, fileInfoId := range other.Order {
|
||||
o.AddOrder(fileInfoId)
|
||||
}
|
||||
|
||||
o.UniqueOrder()
|
||||
}
|
||||
|
||||
func (o *FileInfoList) SortByCreateAt() {
|
||||
sort.Slice(o.Order, func(i, j int) bool {
|
||||
return o.FileInfos[o.Order[i]].CreateAt > o.FileInfos[o.Order[j]].CreateAt
|
||||
})
|
||||
}
|
||||
|
||||
func (o *FileInfoList) Etag() string {
|
||||
id := "0"
|
||||
var t int64 = 0
|
||||
|
||||
for _, v := range o.FileInfos {
|
||||
if v.UpdateAt > t {
|
||||
t = v.UpdateAt
|
||||
id = v.Id
|
||||
} else if v.UpdateAt == t && v.Id > id {
|
||||
t = v.UpdateAt
|
||||
id = v.Id
|
||||
}
|
||||
}
|
||||
|
||||
orderId := ""
|
||||
if len(o.Order) > 0 {
|
||||
orderId = o.Order[0]
|
||||
}
|
||||
|
||||
return Etag(orderId, id, t)
|
||||
}
|
||||
|
||||
func FileInfoListFromJson(data io.Reader) *FileInfoList {
|
||||
var o *FileInfoList
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
37
model/file_info_search_results.go
Обычный файл
37
model/file_info_search_results.go
Обычный файл
@@ -0,0 +1,37 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
)
|
||||
|
||||
type FileInfoSearchMatches map[string][]string
|
||||
|
||||
type FileInfoSearchResults struct {
|
||||
*FileInfoList
|
||||
Matches FileInfoSearchMatches `json:"matches"`
|
||||
}
|
||||
|
||||
func MakeFileInfoSearchResults(fileInfos *FileInfoList, matches FileInfoSearchMatches) *FileInfoSearchResults {
|
||||
return &FileInfoSearchResults{
|
||||
fileInfos,
|
||||
matches,
|
||||
}
|
||||
}
|
||||
|
||||
func (o *FileInfoSearchResults) ToJson() string {
|
||||
b, err := json.Marshal(o)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func FileInfoSearchResultsFromJson(data io.Reader) *FileInfoSearchResults {
|
||||
var o *FileInfoSearchResults
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
return o
|
||||
}
|
||||
@@ -164,6 +164,12 @@ type PostForIndexing struct {
|
||||
ParentCreateAt *int64 `json:"parent_create_at"`
|
||||
}
|
||||
|
||||
type FileForIndexing struct {
|
||||
FileInfo
|
||||
ChannelId string `json:"channel_id"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
// ShallowCopy is an utility function to shallow copy a Post to the given
|
||||
// destination without touching the internal RWMutex.
|
||||
func (o *Post) ShallowCopy(dst *Post) error {
|
||||
|
||||
@@ -25,6 +25,8 @@ type SearchParams struct {
|
||||
ExcludedAfterDate string
|
||||
BeforeDate string
|
||||
ExcludedBeforeDate string
|
||||
Extensions []string
|
||||
ExcludedExtensions []string
|
||||
OnDate string
|
||||
ExcludedDate string
|
||||
OrTerms bool
|
||||
@@ -106,7 +108,7 @@ func (p *SearchParams) GetExcludedDateMillis() (int64, int64) {
|
||||
return GetStartOfDayMillis(date, p.TimeZoneOffset), GetEndOfDayMillis(date, p.TimeZoneOffset)
|
||||
}
|
||||
|
||||
var searchFlags = [...]string{"from", "channel", "in", "before", "after", "on"}
|
||||
var searchFlags = [...]string{"from", "channel", "in", "before", "after", "on", "ext"}
|
||||
|
||||
type flag struct {
|
||||
name string
|
||||
@@ -265,6 +267,8 @@ func ParseSearchParams(text string, timeZoneOffset int) []*SearchParams {
|
||||
excludedBeforeDate := ""
|
||||
onDate := ""
|
||||
excludedDate := ""
|
||||
excludedExtensions := []string{}
|
||||
extensions := []string{}
|
||||
|
||||
for _, flag := range flags {
|
||||
if flag.name == "in" || flag.name == "channel" {
|
||||
@@ -297,6 +301,12 @@ func ParseSearchParams(text string, timeZoneOffset int) []*SearchParams {
|
||||
} else {
|
||||
onDate = flag.value
|
||||
}
|
||||
} else if flag.name == "ext" {
|
||||
if flag.exclude {
|
||||
excludedExtensions = append(excludedExtensions, flag.value)
|
||||
} else {
|
||||
extensions = append(extensions, flag.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,6 +325,8 @@ func ParseSearchParams(text string, timeZoneOffset int) []*SearchParams {
|
||||
ExcludedAfterDate: excludedAfterDate,
|
||||
BeforeDate: beforeDate,
|
||||
ExcludedBeforeDate: excludedBeforeDate,
|
||||
Extensions: extensions,
|
||||
ExcludedExtensions: excludedExtensions,
|
||||
OnDate: onDate,
|
||||
ExcludedDate: excludedDate,
|
||||
TimeZoneOffset: timeZoneOffset,
|
||||
@@ -334,6 +346,8 @@ func ParseSearchParams(text string, timeZoneOffset int) []*SearchParams {
|
||||
ExcludedAfterDate: excludedAfterDate,
|
||||
BeforeDate: beforeDate,
|
||||
ExcludedBeforeDate: excludedBeforeDate,
|
||||
Extensions: extensions,
|
||||
ExcludedExtensions: excludedExtensions,
|
||||
OnDate: onDate,
|
||||
ExcludedDate: excludedDate,
|
||||
TimeZoneOffset: timeZoneOffset,
|
||||
@@ -345,6 +359,7 @@ func ParseSearchParams(text string, timeZoneOffset int) []*SearchParams {
|
||||
len(excludedPlainTerms) == 0 && len(excludedHashtagTerms) == 0 &&
|
||||
(len(inChannels) != 0 || len(fromUsers) != 0 ||
|
||||
len(excludedChannels) != 0 || len(excludedUsers) != 0 ||
|
||||
len(extensions) != 0 || len(excludedExtensions) != 0 ||
|
||||
afterDate != "" || excludedAfterDate != "" ||
|
||||
beforeDate != "" || excludedBeforeDate != "" ||
|
||||
onDate != "" || excludedDate != "") {
|
||||
@@ -360,6 +375,8 @@ func ParseSearchParams(text string, timeZoneOffset int) []*SearchParams {
|
||||
ExcludedAfterDate: excludedAfterDate,
|
||||
BeforeDate: beforeDate,
|
||||
ExcludedBeforeDate: excludedBeforeDate,
|
||||
Extensions: extensions,
|
||||
ExcludedExtensions: excludedExtensions,
|
||||
OnDate: onDate,
|
||||
ExcludedDate: excludedDate,
|
||||
TimeZoneOffset: timeZoneOffset,
|
||||
|
||||
@@ -1043,13 +1043,15 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "words words",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "words words",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "words words",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1058,13 +1060,15 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "-word1 -word2",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "",
|
||||
ExcludedTerms: "word1 word2",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "",
|
||||
ExcludedTerms: "word1 word2",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1073,13 +1077,15 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "\"my stuff\"",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "\"my stuff\"",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "\"my stuff\"",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1088,13 +1094,15 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "-\"my stuff\"",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "",
|
||||
ExcludedTerms: "\"my stuff\"",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "",
|
||||
ExcludedTerms: "\"my stuff\"",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1103,13 +1111,15 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "#words #words",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "#words #words",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: true,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "#words #words",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: true,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1118,22 +1128,26 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "#words words",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "words",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "words",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
{
|
||||
Terms: "#words",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: true,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "#words",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: true,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1142,13 +1156,15 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "-#hashtag",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "",
|
||||
ExcludedTerms: "#hashtag",
|
||||
IsHashtag: true,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "",
|
||||
ExcludedTerms: "#hashtag",
|
||||
IsHashtag: true,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1157,13 +1173,15 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "-#hashtag1 -#hashtag2",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "",
|
||||
ExcludedTerms: "#hashtag1 #hashtag2",
|
||||
IsHashtag: true,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "",
|
||||
ExcludedTerms: "#hashtag1 #hashtag2",
|
||||
IsHashtag: true,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1172,13 +1190,15 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "#hashtag1 -#hashtag2",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "#hashtag1",
|
||||
ExcludedTerms: "#hashtag2",
|
||||
IsHashtag: true,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "#hashtag1",
|
||||
ExcludedTerms: "#hashtag2",
|
||||
IsHashtag: true,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1187,22 +1207,26 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "word1 #hashtag1 -#hashtag2 -word2",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "word1",
|
||||
ExcludedTerms: "word2",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "word1",
|
||||
ExcludedTerms: "word2",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
{
|
||||
Terms: "#hashtag1",
|
||||
ExcludedTerms: "#hashtag2",
|
||||
IsHashtag: true,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "#hashtag1",
|
||||
ExcludedTerms: "#hashtag2",
|
||||
IsHashtag: true,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1211,13 +1235,15 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "in:channel",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{"channel"},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{"channel"},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1226,13 +1252,15 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "-in:channel",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{"channel"},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{"channel"},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1241,13 +1269,15 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "testing in:channel",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{"channel"},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{"channel"},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1256,13 +1286,15 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "testing -in:channel",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{"channel"},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{"channel"},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1271,13 +1303,15 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "in:channel testing",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{"channel"},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{"channel"},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1286,13 +1320,15 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "in:channel in:otherchannel",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{"channel", "otherchannel"},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{"channel", "otherchannel"},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1301,13 +1337,15 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "testing in:channel in:otherchannel",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{"channel", "otherchannel"},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{"channel", "otherchannel"},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1316,13 +1354,15 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "testing in:channel from:someone",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{"channel"},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{"someone"},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{"channel"},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{"someone"},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1331,13 +1371,15 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "testing in:channel -from:someone",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{"channel"},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{"someone"},
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{"channel"},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{"someone"},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1346,13 +1388,15 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "testing in:channel from:someone -from:someoneelse",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{"channel"},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{"someone"},
|
||||
ExcludedUsers: []string{"someoneelse"},
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{"channel"},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{"someone"},
|
||||
ExcludedUsers: []string{"someoneelse"},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1361,13 +1405,15 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "##hashtag +#plus+",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "#hashtag #plus",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: true,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "#hashtag #plus",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: true,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1376,13 +1422,15 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "wildcar*",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "wildcar*",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "wildcar*",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1391,14 +1439,16 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "after:2018-8-1 testing",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
AfterDate: "2018-8-1",
|
||||
ExcludedAfterDate: "",
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
AfterDate: "2018-8-1",
|
||||
ExcludedAfterDate: "",
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1407,14 +1457,16 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "-after:2018-8-1 testing",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
AfterDate: "",
|
||||
ExcludedAfterDate: "2018-8-1",
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
AfterDate: "",
|
||||
ExcludedAfterDate: "2018-8-1",
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1423,15 +1475,17 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "on:2018-8-1 testing",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
OnDate: "2018-8-1",
|
||||
AfterDate: "",
|
||||
ExcludedAfterDate: "",
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
OnDate: "2018-8-1",
|
||||
AfterDate: "",
|
||||
ExcludedAfterDate: "",
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1440,14 +1494,16 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "-on:2018-8-1 testing",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
AfterDate: "",
|
||||
ExcludedDate: "2018-8-1",
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
AfterDate: "",
|
||||
ExcludedDate: "2018-8-1",
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1456,14 +1512,16 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "after:2018-8-1",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "",
|
||||
ExcludedTerms: "",
|
||||
AfterDate: "2018-8-1",
|
||||
ExcludedDate: "",
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "",
|
||||
ExcludedTerms: "",
|
||||
AfterDate: "2018-8-1",
|
||||
ExcludedDate: "",
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1472,15 +1530,17 @@ func TestParseSearchParams(t *testing.T) {
|
||||
Input: "before:2018-8-1",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "",
|
||||
ExcludedTerms: "",
|
||||
BeforeDate: "2018-8-1",
|
||||
AfterDate: "",
|
||||
ExcludedDate: "",
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Terms: "",
|
||||
ExcludedTerms: "",
|
||||
BeforeDate: "2018-8-1",
|
||||
AfterDate: "",
|
||||
ExcludedDate: "",
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1498,6 +1558,110 @@ func TestParseSearchParams(t *testing.T) {
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "input is two words separated with : and should result in a single Extension",
|
||||
Input: "ext:png",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{"png"},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "input is two words separated with :, prefied with - and should result in a single ExcludedExtensions",
|
||||
Input: "-ext:png",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{"png"},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "input is two words separated with : with a prefixed word should result in a single Extension and a term",
|
||||
Input: "testing ext:png",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{"png"},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "input is two words separated with : with a prefixed word should result in a single ExcludedExtension and a term",
|
||||
Input: "testing -ext:png",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{},
|
||||
ExcludedExtensions: []string{"png"},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "input is two words separated with : with a postfix word should result in a single Extension and a term",
|
||||
Input: "ext:png testing",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "testing",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{"png"},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "input is four words separated with : should result in a two Extensions",
|
||||
Input: "ext:png ext:jpg",
|
||||
Output: []*SearchParams{
|
||||
{
|
||||
Terms: "",
|
||||
ExcludedTerms: "",
|
||||
IsHashtag: false,
|
||||
InChannels: []string{},
|
||||
ExcludedChannels: []string{},
|
||||
FromUsers: []string{},
|
||||
ExcludedUsers: []string{},
|
||||
Extensions: []string{"png", "jpg"},
|
||||
ExcludedExtensions: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Ссылка в новой задаче
Block a user