forked from gitea/gitea
feat(topic): search keyword by splitting provided values by , (#4939)
This commit is contained in:
parent
e79e9248fd
commit
486e989a39
|
@ -205,11 +205,14 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err
|
||||||
|
|
||||||
if opts.Keyword != "" {
|
if opts.Keyword != "" {
|
||||||
var keywordCond = builder.NewCond()
|
var keywordCond = builder.NewCond()
|
||||||
if opts.TopicOnly {
|
// separate keyword
|
||||||
keywordCond = keywordCond.Or(builder.Like{"topic.name", strings.ToLower(opts.Keyword)})
|
for _, v := range strings.Split(opts.Keyword, ",") {
|
||||||
} else {
|
if opts.TopicOnly {
|
||||||
keywordCond = keywordCond.Or(builder.Like{"lower_name", strings.ToLower(opts.Keyword)})
|
keywordCond = keywordCond.Or(builder.Like{"topic.name", strings.ToLower(v)})
|
||||||
keywordCond = keywordCond.Or(builder.Like{"topic.name", strings.ToLower(opts.Keyword)})
|
} else {
|
||||||
|
keywordCond = keywordCond.Or(builder.Like{"lower_name", strings.ToLower(v)})
|
||||||
|
keywordCond = keywordCond.Or(builder.Like{"topic.name", strings.ToLower(v)})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cond = cond.And(keywordCond)
|
cond = cond.And(keywordCond)
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,6 +237,9 @@ func TestSearchRepositoryByTopicName(t *testing.T) {
|
||||||
{name: "AllPublic/OnlySearchPublicRepositoriesFromTopic",
|
{name: "AllPublic/OnlySearchPublicRepositoriesFromTopic",
|
||||||
opts: &SearchRepoOptions{OwnerID: 21, AllPublic: true, Keyword: "graphql", TopicOnly: true},
|
opts: &SearchRepoOptions{OwnerID: 21, AllPublic: true, Keyword: "graphql", TopicOnly: true},
|
||||||
count: 1},
|
count: 1},
|
||||||
|
{name: "AllPublic/OnlySearchMultipleKeywordPublicRepositoriesFromTopic",
|
||||||
|
opts: &SearchRepoOptions{OwnerID: 21, AllPublic: true, Keyword: "graphql,golang", TopicOnly: true},
|
||||||
|
count: 3},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
|
|
Loading…
Reference in New Issue