From 486e989a3979684ba428a129492881de12ec923a Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Thu, 18 Oct 2018 11:14:28 +0800 Subject: [PATCH] feat(topic): search keyword by splitting provided values by , (#4939) --- models/repo_list.go | 13 ++++++++----- models/repo_list_test.go | 3 +++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/models/repo_list.go b/models/repo_list.go index c7e292d8a9..4368057e04 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -205,11 +205,14 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err if opts.Keyword != "" { var keywordCond = builder.NewCond() - if opts.TopicOnly { - keywordCond = keywordCond.Or(builder.Like{"topic.name", strings.ToLower(opts.Keyword)}) - } else { - keywordCond = keywordCond.Or(builder.Like{"lower_name", strings.ToLower(opts.Keyword)}) - keywordCond = keywordCond.Or(builder.Like{"topic.name", strings.ToLower(opts.Keyword)}) + // separate keyword + for _, v := range strings.Split(opts.Keyword, ",") { + if opts.TopicOnly { + keywordCond = keywordCond.Or(builder.Like{"topic.name", strings.ToLower(v)}) + } 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) } diff --git a/models/repo_list_test.go b/models/repo_list_test.go index 8f4947dbb2..2f9a149188 100644 --- a/models/repo_list_test.go +++ b/models/repo_list_test.go @@ -237,6 +237,9 @@ func TestSearchRepositoryByTopicName(t *testing.T) { {name: "AllPublic/OnlySearchPublicRepositoriesFromTopic", opts: &SearchRepoOptions{OwnerID: 21, AllPublic: true, Keyword: "graphql", TopicOnly: true}, count: 1}, + {name: "AllPublic/OnlySearchMultipleKeywordPublicRepositoriesFromTopic", + opts: &SearchRepoOptions{OwnerID: 21, AllPublic: true, Keyword: "graphql,golang", TopicOnly: true}, + count: 3}, } for _, testCase := range testCases {