adding search func

This commit is contained in:
mr
2024-07-26 13:45:10 +02:00
parent 6c83e54d37
commit 8c97fca96c
12 changed files with 170 additions and 1 deletions

View File

@@ -53,3 +53,20 @@ func (wfa DataMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
}
return objs, 200, nil
}
func (wfa *DataMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.Search(word, []string{"name", "short_description", "description", "owner", "source_url"}, wfa.GetType())
if err != nil {
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
return nil, code, err
}
var results []DataResource
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
return nil, 404, err
}
for _, r := range results {
objs = append(objs, &r.AbstractResource)
}
return objs, 200, nil
}