|
|
@@ -126,25 +126,23 @@ func SearchDataset(opts *SearchDatasetOptions) (DatasetList, int64, error) { |
|
|
|
|
|
|
|
func SearchDatasetCondition(opts *SearchDatasetOptions) builder.Cond { |
|
|
|
var cond = builder.NewCond() |
|
|
|
cond = cond.And(builder.Neq{"status": DatasetStatusDeleted}) |
|
|
|
cond = cond.And(builder.Neq{"dataset.status": DatasetStatusDeleted}) |
|
|
|
|
|
|
|
if len(opts.Keyword) > 0 { |
|
|
|
cond = cond.And(builder.Like{"title", opts.Keyword}) |
|
|
|
cond = cond.And(builder.Like{"dataset.title", opts.Keyword}) |
|
|
|
} |
|
|
|
|
|
|
|
if opts.RepoID > 0 { |
|
|
|
cond = cond.And(builder.Eq{"repo_id": opts.RepoID}) |
|
|
|
cond = cond.And(builder.Eq{"dataset.repo_id": opts.RepoID}) |
|
|
|
} |
|
|
|
|
|
|
|
if opts.IncludePublic { |
|
|
|
cond = cond.And(builder.Eq{"status": DatasetStatusPublic}) |
|
|
|
cond = cond.And(builder.Eq{"dataset.status": DatasetStatusPublic}) |
|
|
|
if opts.OwnerID > 0 { |
|
|
|
cond = cond.Or(builder.Eq{"user_id": opts.OwnerID}) |
|
|
|
} |
|
|
|
} else { |
|
|
|
if opts.OwnerID > 0 { |
|
|
|
cond = cond.And(builder.Eq{"user_id": opts.OwnerID}) |
|
|
|
cond = cond.Or(builder.Eq{"repository.owner_id": opts.OwnerID}) |
|
|
|
} |
|
|
|
} else if opts.OwnerID > 0 { |
|
|
|
cond = cond.And(builder.Eq{"repository.owner_id": opts.OwnerID}) |
|
|
|
} |
|
|
|
|
|
|
|
return cond |
|
|
@@ -161,12 +159,13 @@ func SearchDatasetByCondition(opts *SearchDatasetOptions, cond builder.Cond) (Da |
|
|
|
|
|
|
|
datasets := make(DatasetList, 0, opts.PageSize) |
|
|
|
|
|
|
|
count, err := sess.Where(cond).Count(new(Dataset)) |
|
|
|
count, err := sess.Join("INNER", "repository", "repository.id = dataset.repo_id").Where(cond).Count(new(Dataset)) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return nil, 0, fmt.Errorf("Count: %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
sess.Where(cond).OrderBy(opts.SearchOrderBy.String()) |
|
|
|
sess.Select("dataset.*").Join("INNER", "repository", "repository.id = dataset.repo_id").Where(cond).OrderBy(opts.SearchOrderBy.String()) |
|
|
|
if opts.PageSize > 0 { |
|
|
|
sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize) |
|
|
|
} |
|
|
|