Skip to content

Commit 486e989

Browse files
appleboytechknowlogick
authored andcommitted
feat(topic): search keyword by splitting provided values by , (#4939)
1 parent e79e924 commit 486e989

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

models/repo_list.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,14 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err
205205

206206
if opts.Keyword != "" {
207207
var keywordCond = builder.NewCond()
208-
if opts.TopicOnly {
209-
keywordCond = keywordCond.Or(builder.Like{"topic.name", strings.ToLower(opts.Keyword)})
210-
} else {
211-
keywordCond = keywordCond.Or(builder.Like{"lower_name", strings.ToLower(opts.Keyword)})
212-
keywordCond = keywordCond.Or(builder.Like{"topic.name", strings.ToLower(opts.Keyword)})
208+
// separate keyword
209+
for _, v := range strings.Split(opts.Keyword, ",") {
210+
if opts.TopicOnly {
211+
keywordCond = keywordCond.Or(builder.Like{"topic.name", strings.ToLower(v)})
212+
} else {
213+
keywordCond = keywordCond.Or(builder.Like{"lower_name", strings.ToLower(v)})
214+
keywordCond = keywordCond.Or(builder.Like{"topic.name", strings.ToLower(v)})
215+
}
213216
}
214217
cond = cond.And(keywordCond)
215218
}

models/repo_list_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ func TestSearchRepositoryByTopicName(t *testing.T) {
237237
{name: "AllPublic/OnlySearchPublicRepositoriesFromTopic",
238238
opts: &SearchRepoOptions{OwnerID: 21, AllPublic: true, Keyword: "graphql", TopicOnly: true},
239239
count: 1},
240+
{name: "AllPublic/OnlySearchMultipleKeywordPublicRepositoriesFromTopic",
241+
opts: &SearchRepoOptions{OwnerID: 21, AllPublic: true, Keyword: "graphql,golang", TopicOnly: true},
242+
count: 3},
240243
}
241244

242245
for _, testCase := range testCases {

0 commit comments

Comments
 (0)