Skip to content

Commit 0d2dd17

Browse files
committed
fix tests
1 parent 9c5fce4 commit 0d2dd17

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

models/repo_list.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,23 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, err
202202
}
203203

204204
if opts.Keyword != "" {
205-
var keywordCond = builder.NewCond()
206205
// separate keyword
206+
var subQueryCond = builder.NewCond()
207207
for _, v := range strings.Split(opts.Keyword, ",") {
208-
subQuery := builder.Select("repo_topic.repo_id").From("repo_topic").
209-
Join("INNER", "topic", "topic.id = repo_topic.topic_id").
210-
Where(builder.Like{"topic.name", strings.ToLower(v)}).
211-
GroupBy("repo_topic.repo_id")
212-
keywordCond = keywordCond.Or(builder.In("id", subQuery))
213-
if !opts.TopicOnly {
214-
keywordCond = keywordCond.Or(builder.Like{"lower_name", strings.ToLower(v)})
208+
subQueryCond = subQueryCond.Or(builder.Like{"topic.name", strings.ToLower(v)})
209+
}
210+
subQuery := builder.Select("repo_topic.repo_id").From("repo_topic").
211+
Join("INNER", "topic", "topic.id = repo_topic.topic_id").
212+
Where(subQueryCond).
213+
GroupBy("repo_topic.repo_id")
214+
215+
var keywordCond = builder.In("id", subQuery)
216+
if !opts.TopicOnly {
217+
var likes = builder.NewCond()
218+
for _, v := range strings.Split(opts.Keyword, ",") {
219+
likes = likes.Or(builder.Like{"lower_name", strings.ToLower(v)})
215220
}
221+
keywordCond = keywordCond.Or(likes)
216222
}
217223
cond = cond.And(keywordCond)
218224
}

models/repo_list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func TestSearchRepositoryByTopicName(t *testing.T) {
239239
count: 1},
240240
{name: "AllPublic/OnlySearchMultipleKeywordPublicRepositoriesFromTopic",
241241
opts: &SearchRepoOptions{OwnerID: 21, AllPublic: true, Keyword: "graphql,golang", TopicOnly: true},
242-
count: 3},
242+
count: 2},
243243
}
244244

245245
for _, testCase := range testCases {

0 commit comments

Comments
 (0)