fix-3936
into zouap_roshmci
1 year ago
@@ -181,6 +181,10 @@ type SearchRepoOptions struct { | |||||
TopicOnly bool | TopicOnly bool | ||||
//search by Specific TopicName | //search by Specific TopicName | ||||
TopicName string | 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 | // include description in keyword search | ||||
IncludeDescription bool | IncludeDescription bool | ||||
// None -> include has milestones AND has no milestone | // None -> include has milestones AND has no milestone | ||||
@@ -407,6 +411,18 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond { | |||||
var topicNameCond = builder.In("id", subQuery) | var topicNameCond = builder.In("id", subQuery) | ||||
cond = cond.And(topicNameCond) | 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 { | if opts.Fork != util.OptionalBoolNone { | ||||
@@ -8,6 +8,7 @@ package routers | |||||
import ( | import ( | ||||
"bytes" | "bytes" | ||||
"encoding/json" | "encoding/json" | ||||
"errors" | |||||
"net/http" | "net/http" | ||||
"strconv" | "strconv" | ||||
"strings" | "strings" | ||||
@@ -393,14 +394,22 @@ func RepoFind(ctx *context.Context) { | |||||
ownerID = ctx.User.ID | 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{ | 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 { | if err != nil { | ||||
log.Error("RepoFind error. %v", err) | log.Error("RepoFind error. %v", err) | ||||
@@ -409,6 +418,25 @@ func RepoFind(ctx *context.Context) { | |||||
} | } | ||||
ctx.JSON(http.StatusOK, response.SuccessWithData(result)) | 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) { | func ExploreMyDatasets(ctx *context.Context) { | ||||
opts := &models.SearchDatasetOptions{ | opts := &models.SearchDatasetOptions{ | ||||
UploadAttachmentByMe: true, | UploadAttachmentByMe: true, | ||||
@@ -163,13 +163,14 @@ func GetHotPaperRepos() ([]*models.Repository4Card, error) { | |||||
type FindReposOptions struct { | type FindReposOptions struct { | ||||
models.ListOptions | 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) { | func FindRepos(opts FindReposOptions) (*models.FindReposResponse, error) { | ||||
@@ -223,7 +224,8 @@ func FindRepos(opts FindReposOptions) (*models.FindReposResponse, error) { | |||||
OwnerID: opts.OwnerID, | OwnerID: opts.OwnerID, | ||||
AllPublic: true, | AllPublic: true, | ||||
AllLimited: true, | AllLimited: true, | ||||
TopicName: opts.Topic, | |||||
MultiTopicNames: opts.Topics, | |||||
IsTopicIntersect: opts.IsTopicIntersect, | |||||
IncludeDescription: setting.UI.SearchRepoDescription, | IncludeDescription: setting.UI.SearchRepoDescription, | ||||
RepoIds: opts.RepoIds, | RepoIds: opts.RepoIds, | ||||
}) | }) | ||||
@@ -125,7 +125,7 @@ func SearchRepoInfoWithInstitution(opt *models.SearchRepoOpt) ([]*models.RepoWit | |||||
ListOptions: models.ListOptions{Page: opt.Page, PageSize: opt.PageSize}, | ListOptions: models.ListOptions{Page: opt.Page, PageSize: opt.PageSize}, | ||||
Sort: opt.OrderBy, | Sort: opt.OrderBy, | ||||
Keyword: opt.Q, | Keyword: opt.Q, | ||||
Topic: opt.Topic, | |||||
Topics: []string{opt.Topic}, | |||||
RepoIds: repoIds, | RepoIds: repoIds, | ||||
}) | }) | ||||
@@ -164,7 +164,6 @@ func getRepoIdAndInstitutionMap(infos []*models.RepoConvergeInfo) ([]int64, map[ | |||||
return repoIds, institutionMap | return repoIds, institutionMap | ||||
} | } | ||||
func IsValidRepoConvergeExists(repoId, baseInfoId int64) (bool, error) { | func IsValidRepoConvergeExists(repoId, baseInfoId int64) (bool, error) { | ||||
list, err := models.GetRepoConverge(models.GetRepoConvergeOpts{ | list, err := models.GetRepoConverge(models.GetRepoConvergeOpts{ | ||||
Status: []int{models.TechHide, models.TechShow, models.TechMigrating}, | Status: []int{models.TechHide, models.TechShow, models.TechMigrating}, | ||||
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》