Browse Source

Merge pull request 'fix 428后端代码合入' (#514) from fix-333 into V20211018

Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/514
Reviewed-by: lewis <747342561@qq.com>
tags/v1.21.10.1^2
lewis 4 years ago
parent
commit
59526b1cc1
2 changed files with 16 additions and 3 deletions
  1. +14
    -0
      models/repo_list.go
  2. +2
    -3
      routers/home.go

+ 14
- 0
models/repo_list.go View File

@@ -166,6 +166,8 @@ type SearchRepoOptions struct {
Archived util.OptionalBool
// only search topic name
TopicOnly bool
//search by Specific TopicName
TopicName string
// include description in keyword search
IncludeDescription bool
// None -> include has milestones AND has no milestone
@@ -327,6 +329,18 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
}
cond = cond.And(keywordCond)
}
if opts.TopicName != "" {
var subQueryCond = builder.NewCond()
subQueryCond = subQueryCond.Or(builder.Eq{"topic.name": opts.TopicName})
subQuery := builder.Select("repo_topic.repo_id").From("repo_topic").
Join("INNER", "topic", "topic.id = repo_topic.topic_id").
Where(subQueryCond).
GroupBy("repo_topic.repo_id")

var topicNameCond = builder.In("id", subQuery)
cond = cond.And(topicNameCond)

}

if opts.Fork != util.OptionalBoolNone {
cond = cond.And(builder.Eq{"is_fork": opts.Fork == util.OptionalBoolTrue})


+ 2
- 3
routers/home.go View File

@@ -149,8 +149,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {

//todo:support other topics
keyword := strings.Trim(ctx.Query("q"), " ")
topicOnly := ctx.QueryBool("topic")
ctx.Data["TopicOnly"] = topicOnly
topic := strings.Trim(ctx.Query("topic"), " ")

repos, count, err = models.SearchRepository(&models.SearchRepoOptions{
ListOptions: models.ListOptions{
@@ -164,7 +163,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
OwnerID: opts.OwnerID,
AllPublic: true,
AllLimited: true,
TopicOnly: topicOnly,
TopicName: topic,
IncludeDescription: setting.UI.SearchRepoDescription,
})
if err != nil {


Loading…
Cancel
Save