|
|
|
@@ -139,20 +139,7 @@ func SearchDatasetCondition(opts *SearchDatasetOptions) builder.Cond { |
|
|
|
var cond = builder.NewCond() |
|
|
|
cond = cond.And(builder.Neq{"dataset.status": DatasetStatusDeleted}) |
|
|
|
|
|
|
|
if len(opts.Keyword) > 0 { |
|
|
|
cond = cond.And(builder.Or(builder.Like{"dataset.title", opts.Keyword}, builder.Like{"dataset.description", opts.Keyword})) |
|
|
|
} |
|
|
|
|
|
|
|
if len(opts.Category) > 0 { |
|
|
|
cond = cond.And(builder.Eq{"dataset.category": opts.Category}) |
|
|
|
} |
|
|
|
|
|
|
|
if len(opts.Task) > 0 { |
|
|
|
cond = cond.And(builder.Eq{"dataset.task": opts.Task}) |
|
|
|
} |
|
|
|
if len(opts.License) > 0 { |
|
|
|
cond = cond.And(builder.Eq{"dataset.license": opts.License}) |
|
|
|
} |
|
|
|
cond = generateFilterCond(opts, cond) |
|
|
|
|
|
|
|
if opts.RepoID > 0 { |
|
|
|
cond = cond.And(builder.Eq{"dataset.repo_id": opts.RepoID}) |
|
|
|
@@ -162,14 +149,12 @@ func SearchDatasetCondition(opts *SearchDatasetOptions) builder.Cond { |
|
|
|
cond = cond.And(builder.Eq{"dataset.status": DatasetStatusPublic}) |
|
|
|
cond = cond.And(builder.Eq{"attachment.is_private": false}) |
|
|
|
if opts.OwnerID > 0 { |
|
|
|
if len(opts.Keyword) == 0 { |
|
|
|
cond = cond.Or(builder.Eq{"repository.owner_id": opts.OwnerID}) |
|
|
|
} else { |
|
|
|
subCon := builder.NewCond() |
|
|
|
subCon = subCon.And(builder.Eq{"repository.owner_id": opts.OwnerID}, builder.Or(builder.Like{"dataset.title", opts.Keyword}, builder.Like{"dataset.description", opts.Keyword})) |
|
|
|
cond = cond.Or(subCon) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
subCon := builder.NewCond() |
|
|
|
subCon = subCon.And(builder.Eq{"repository.owner_id": opts.OwnerID}) |
|
|
|
subCon = generateFilterCond(opts, subCon) |
|
|
|
cond = cond.Or(subCon) |
|
|
|
|
|
|
|
} |
|
|
|
} else if opts.OwnerID > 0 { |
|
|
|
cond = cond.And(builder.Eq{"repository.owner_id": opts.OwnerID}) |
|
|
|
@@ -182,6 +167,25 @@ func SearchDatasetCondition(opts *SearchDatasetOptions) builder.Cond { |
|
|
|
return cond |
|
|
|
} |
|
|
|
|
|
|
|
func generateFilterCond(opts *SearchDatasetOptions, cond builder.Cond) builder.Cond { |
|
|
|
if len(opts.Keyword) > 0 { |
|
|
|
cond = cond.And(builder.Or(builder.Like{"dataset.title", opts.Keyword}, builder.Like{"dataset.description", opts.Keyword})) |
|
|
|
} |
|
|
|
|
|
|
|
if len(opts.Category) > 0 { |
|
|
|
cond = cond.And(builder.Eq{"dataset.category": opts.Category}) |
|
|
|
} |
|
|
|
|
|
|
|
if len(opts.Task) > 0 { |
|
|
|
cond = cond.And(builder.Eq{"dataset.task": opts.Task}) |
|
|
|
} |
|
|
|
if len(opts.License) > 0 { |
|
|
|
cond = cond.And(builder.Eq{"dataset.license": opts.License}) |
|
|
|
} |
|
|
|
|
|
|
|
return cond |
|
|
|
} |
|
|
|
|
|
|
|
func SearchDatasetByCondition(opts *SearchDatasetOptions, cond builder.Cond) (DatasetList, int64, error) { |
|
|
|
if opts.Page <= 0 { |
|
|
|
opts.Page = 1 |
|
|
|
|