]> source.dussan.org Git - gitea.git/commitdiff
feat(topic): search keyword by splitting provided values by , (#4939)
authorBo-Yi Wu <appleboy.tw@gmail.com>
Thu, 18 Oct 2018 03:14:28 +0000 (11:14 +0800)
committertechknowlogick <hello@techknowlogick.com>
Thu, 18 Oct 2018 03:14:28 +0000 (23:14 -0400)
models/repo_list.go
models/repo_list_test.go

index c7e292d8a9eab305f1b782dfe66bf239842174b1..4368057e04fe02fb210a45d905c18816275f1a46 100644 (file)
@@ -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)
        }
index 8f4947dbb22cb30158e9948d6b076c897fd9a290..2f9a1491887b901b408332211796fd5745ca464e 100644 (file)
@@ -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 {