COMPLEX SEARCH
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package processing
|
||||
|
||||
import (
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
@@ -44,7 +45,7 @@ func (pma *processingMongoAccessor) LoadOne(id string) (utils.DBObject, int, err
|
||||
|
||||
res_mongo.Decode(&processing)
|
||||
accessor := (&resource_model.ResourceModel{}).GetAccessor()
|
||||
resources, _, err := accessor.Search(pma.GetType())
|
||||
resources, _, err := accessor.Search(nil, pma.GetType())
|
||||
if err == nil && len(resources) > 0 {
|
||||
processing.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
@@ -63,7 +64,7 @@ func (wfa processingMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, erro
|
||||
return nil, 404, err
|
||||
}
|
||||
accessor := (&resource_model.ResourceModel{}).GetAccessor()
|
||||
resources, _, err := accessor.Search(wfa.GetType())
|
||||
resources, _, err := accessor.Search(nil, wfa.GetType())
|
||||
for _, r := range results {
|
||||
if err == nil && len(resources) > 0 {
|
||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
@@ -73,12 +74,20 @@ func (wfa processingMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, erro
|
||||
return objs, 200, nil
|
||||
}
|
||||
|
||||
func (wfa *processingMongoAccessor) Search(word string, options ...string) ([]utils.ShallowDBObject, int, error) {
|
||||
func (wfa *processingMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
|
||||
objs := []utils.ShallowDBObject{}
|
||||
if len(options) == 0 {
|
||||
options = []string{"abstractresource.abstractobject.name", "abstractresource.short_description", "abstractresource.description", "abstractresource.owner", "abstractresource.source_url"}
|
||||
if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" {
|
||||
filters = &dbs.Filters{
|
||||
Or: map[string]dbs.Filter{
|
||||
"abstractresource.abstractobject.name": {Operator: dbs.LIKE.String(), Value: search},
|
||||
"abstractresource.short_description": {Operator: dbs.LIKE.String(), Value: search},
|
||||
"abstractresource.description": {Operator: dbs.LIKE.String(), Value: search},
|
||||
"abstractresource.owner": {Operator: dbs.LIKE.String(), Value: search},
|
||||
"abstractresource.source_url": {Operator: dbs.LIKE.String(), Value: search},
|
||||
},
|
||||
}
|
||||
}
|
||||
res_mongo, code, err := mongo.MONGOService.Search(word, options, wfa.GetType())
|
||||
res_mongo, code, err := mongo.MONGOService.Search(*filters, wfa.GetType())
|
||||
if err != nil {
|
||||
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
|
||||
return nil, code, err
|
||||
@@ -88,7 +97,7 @@ func (wfa *processingMongoAccessor) Search(word string, options ...string) ([]ut
|
||||
return nil, 404, err
|
||||
}
|
||||
accessor := (&resource_model.ResourceModel{}).GetAccessor()
|
||||
resources, _, err := accessor.Search(wfa.GetType())
|
||||
resources, _, err := accessor.Search(nil, wfa.GetType())
|
||||
for _, r := range results {
|
||||
if err == nil && len(resources) > 0 {
|
||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
|
Reference in New Issue
Block a user