#3957 #3936 增加根据多个标签筛选项目列表的接口

Merged
chenshihai merged 2 commits from fix-3936 into zouap_roshmci 1 year ago
  1. +16
    -0
      models/repo_list.go
  2. +35
    -7
      routers/home.go
  3. +10
    -8
      services/repository/square.go
  4. +1
    -2
      services/tech/tech.go

+ 16
- 0
models/repo_list.go View File

@@ -181,6 +181,10 @@ type SearchRepoOptions struct {
TopicOnly bool
//search by Specific TopicName
TopicName string
//Multi topic names.available just when topicName is empty
MultiTopicNames []string
//available just when MultiTopicNames is not empty,true for intersect,false for union
IsTopicIntersect bool
// include description in keyword search
IncludeDescription bool
// None -> include has milestones AND has no milestone
@@ -407,6 +411,18 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
var topicNameCond = builder.In("id", subQuery)
cond = cond.And(topicNameCond)

} else if opts.MultiTopicNames != nil && len(opts.MultiTopicNames) > 0 {
var subQueryCond = builder.NewCond()
subQueryCond = subQueryCond.And(builder.In("topic.name", opts.MultiTopicNames))
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")
if opts.IsTopicIntersect {
subQuery = subQuery.Having(fmt.Sprintf("count(repo_topic.repo_id) >= %d", len(opts.MultiTopicNames)))
}
var topicNameCond = builder.In("id", subQuery)
cond = cond.And(topicNameCond)
}

if opts.Fork != util.OptionalBoolNone {


+ 35
- 7
routers/home.go View File

@@ -8,6 +8,7 @@ package routers
import (
"bytes"
"encoding/json"
"errors"
"net/http"
"strconv"
"strings"
@@ -393,14 +394,22 @@ func RepoFind(ctx *context.Context) {
ownerID = ctx.User.ID
}

topics, isIntersect, err := handleTopic4RepoFind(topic)
if err != nil {
log.Error("RepoFind handleTopic4RepoFind err.topicStr=%s err=%v", topic, err)
ctx.JSON(http.StatusOK, response.ResponseError(err))
return
}

result, err := repository.FindRepos(repository.FindReposOptions{
ListOptions: models.ListOptions{Page: page, PageSize: pageSize},
Actor: ctx.User,
Sort: sort,
Keyword: keyword,
Topic: topic,
Private: ctx.User != nil,
OwnerID: ownerID,
ListOptions: models.ListOptions{Page: page, PageSize: pageSize},
Actor: ctx.User,
Sort: sort,
Keyword: keyword,
Topics: topics,
IsTopicIntersect: isIntersect,
Private: ctx.User != nil,
OwnerID: ownerID,
})
if err != nil {
log.Error("RepoFind error. %v", err)
@@ -409,6 +418,25 @@ func RepoFind(ctx *context.Context) {
}
ctx.JSON(http.StatusOK, response.SuccessWithData(result))
}

const UnionSeparator = "|"
const IntersectSeparator = "*"

func handleTopic4RepoFind(topicStr string) ([]string, bool, error) {
topicStr = strings.ReplaceAll(topicStr, " ", "")
if topicStr == "" {
return []string{}, false, nil
}
if strings.Contains(topicStr, UnionSeparator) && strings.Contains(topicStr, IntersectSeparator) {
return nil, false, errors.New("topic format error")
}
if strings.Contains(topicStr, IntersectSeparator) {
return strings.Split(topicStr, IntersectSeparator), true, nil
}
return strings.Split(topicStr, UnionSeparator), false, nil

}

func ExploreMyDatasets(ctx *context.Context) {
opts := &models.SearchDatasetOptions{
UploadAttachmentByMe: true,


+ 10
- 8
services/repository/square.go View File

@@ -163,13 +163,14 @@ func GetHotPaperRepos() ([]*models.Repository4Card, error) {

type FindReposOptions struct {
models.ListOptions
Actor *models.User
Sort string
Keyword string
Topic string
Private bool
OwnerID int64
RepoIds []int64
Actor *models.User
Sort string
Keyword string
Topics []string
IsTopicIntersect bool
Private bool
OwnerID int64
RepoIds []int64
}

func FindRepos(opts FindReposOptions) (*models.FindReposResponse, error) {
@@ -223,7 +224,8 @@ func FindRepos(opts FindReposOptions) (*models.FindReposResponse, error) {
OwnerID: opts.OwnerID,
AllPublic: true,
AllLimited: true,
TopicName: opts.Topic,
MultiTopicNames: opts.Topics,
IsTopicIntersect: opts.IsTopicIntersect,
IncludeDescription: setting.UI.SearchRepoDescription,
RepoIds: opts.RepoIds,
})


+ 1
- 2
services/tech/tech.go View File

@@ -125,7 +125,7 @@ func SearchRepoInfoWithInstitution(opt *models.SearchRepoOpt) ([]*models.RepoWit
ListOptions: models.ListOptions{Page: opt.Page, PageSize: opt.PageSize},
Sort: opt.OrderBy,
Keyword: opt.Q,
Topic: opt.Topic,
Topics: []string{opt.Topic},
RepoIds: repoIds,
})

@@ -164,7 +164,6 @@ func getRepoIdAndInstitutionMap(infos []*models.RepoConvergeInfo) ([]int64, map[
return repoIds, institutionMap
}


func IsValidRepoConvergeExists(repoId, baseInfoId int64) (bool, error) {
list, err := models.GetRepoConverge(models.GetRepoConvergeOpts{
Status: []int{models.TechHide, models.TechShow, models.TechMigrating},


Loading…
Cancel
Save