From 39c324bd6deba2c3afba700fb0e5c56fd0d204d3 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 23 Sep 2020 13:41:09 +0300 Subject: [PATCH] [#39] service/object: Add query filters to search right child Signed-off-by: Leonard Lyubich --- pkg/services/object/search/query/v1/keys.go | 27 +++++++++++++++++++++ pkg/services/object/search/query/v1/v1.go | 4 +++ 2 files changed, 31 insertions(+) create mode 100644 pkg/services/object/search/query/v1/keys.go diff --git a/pkg/services/object/search/query/v1/keys.go b/pkg/services/object/search/query/v1/keys.go new file mode 100644 index 000000000..6cf5d386f --- /dev/null +++ b/pkg/services/object/search/query/v1/keys.go @@ -0,0 +1,27 @@ +package query + +import ( + "github.com/nspcc-dev/neofs-api-go/pkg/object" + "github.com/nspcc-dev/neofs-node/pkg/services/object/search/query" +) + +// FIXME: this is a temporary solution for object fields filters + +const keyChildrenField = "Object.Header.Split.Children" + +const keyParentIDField = "Object.Header.Split.Parent" + +func NewEmptyChildrenFilter() *Filter { + return NewFilterEqual(keyChildrenField, "") +} + +func NewParentIDFilter(par *object.ID) *Filter { + return NewFilterEqual(keyParentIDField, idValue(par)) +} + +func NewRightChildQuery(par *object.ID) query.Query { + return New( + NewParentIDFilter(par), + NewEmptyChildrenFilter(), + ) +} diff --git a/pkg/services/object/search/query/v1/v1.go b/pkg/services/object/search/query/v1/v1.go index 0aff37722..742d46528 100644 --- a/pkg/services/object/search/query/v1/v1.go +++ b/pkg/services/object/search/query/v1/v1.go @@ -97,6 +97,10 @@ func headerEqual(obj *object.Object, key, value string) bool { return value == cidValue(obj.GetContainerID()) case objectSDK.HdrSysNameOwnerID: return value == ownerIDValue(obj.GetOwnerID()) + case keyChildrenField: + return len(obj.GetChildren()) == 0 + case keyParentIDField: + return idValue(obj.GetParent().GetID()) == value // TODO: add other headers } }