[#58] object/search: Add object-with-children filter

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-10-01 12:02:53 +03:00 committed by Alex Vanin
parent 624e8cd3cb
commit 16252ad09a
2 changed files with 14 additions and 3 deletions

View file

@ -7,12 +7,14 @@ import (
// FIXME: this is a temporary solution for object fields filters
const keyChildrenField = "Object.Header.Split.Children"
const keyParentField = "Object.Header.Split.WithChildren"
const keyNoChildrenField = "Object.Header.Split.NoChildren"
const keyParentIDField = "Object.Header.Split.Parent"
func NewEmptyChildrenFilter() *Filter {
return NewFilterEqual(keyChildrenField, "")
return NewFilterEqual(keyNoChildrenField, "")
}
func NewParentIDFilter(par *object.ID) *Filter {
@ -25,3 +27,10 @@ func NewRightChildQuery(par *object.ID) query.Query {
NewEmptyChildrenFilter(),
)
}
func NewLinkingQuery(par *object.ID) query.Query {
return New(
NewParentIDFilter(par),
NewFilterEqual(keyParentField, ""),
)
}

View file

@ -97,10 +97,12 @@ func headerEqual(obj *object.Object, key, value string) bool {
return value == cidValue(obj.GetContainerID())
case objectSDK.HdrSysNameOwnerID:
return value == ownerIDValue(obj.GetOwnerID())
case keyChildrenField:
case keyNoChildrenField:
return len(obj.GetChildren()) == 0
case keyParentIDField:
return idValue(obj.GetParent().GetID()) == value
case keyParentField:
return len(obj.GetChildren()) > 0
// TODO: add other headers
}
}