From 8d931b81a6e1d9c17c7d684db88ebcb6a0e172df Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 29 Oct 2020 17:57:07 +0300 Subject: [PATCH] [#125] object/search: Use latest search filter keys Signed-off-by: Leonard Lyubich --- pkg/services/object/search/query/v1/keys.go | 15 ++++-------- pkg/services/object/search/query/v1/v1.go | 23 ++++++++----------- .../object/search/query/v1/v1_test.go | 22 ++---------------- 3 files changed, 17 insertions(+), 43 deletions(-) diff --git a/pkg/services/object/search/query/v1/keys.go b/pkg/services/object/search/query/v1/keys.go index f4a43e960e..cd062ce117 100644 --- a/pkg/services/object/search/query/v1/keys.go +++ b/pkg/services/object/search/query/v1/keys.go @@ -2,24 +2,19 @@ package query import ( "github.com/nspcc-dev/neofs-api-go/pkg/object" + v2object "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-node/pkg/services/object/search/query" ) // FIXME: this is a temporary solution for object fields filters -const keyParentField = "Object.Header.Split.WithChildren" - -const keyNoChildrenField = "Object.Header.Split.NoChildren" - -const keyParentIDField = "Object.Header.Split.Parent" - func NewRightChildQuery(par *object.ID) query.Query { q := &Query{ filters: make(object.SearchFilters, 0, 2), } - q.filters.AddFilter(keyParentIDField, idValue(par), object.MatchStringEqual) - q.filters.AddFilter(keyNoChildrenField, "", object.MatchStringEqual) + q.filters.AddFilter(v2object.FilterHeaderParent, idValue(par), object.MatchStringEqual) + q.filters.AddFilter(v2object.FilterPropertyChildfree, v2object.BooleanPropertyValueTrue, object.MatchStringEqual) return q } @@ -29,8 +24,8 @@ func NewLinkingQuery(par *object.ID) query.Query { filters: make(object.SearchFilters, 0, 2), } - q.filters.AddFilter(keyParentIDField, idValue(par), object.MatchStringEqual) - q.filters.AddFilter(keyParentField, "", object.MatchStringEqual) + q.filters.AddFilter(v2object.FilterHeaderParent, idValue(par), object.MatchStringEqual) + q.filters.AddFilter(v2object.FilterPropertyChildfree, v2object.BooleanPropertyValueFalse, object.MatchStringEqual) return q } diff --git a/pkg/services/object/search/query/v1/v1.go b/pkg/services/object/search/query/v1/v1.go index ba1fd13291..cd136e0614 100644 --- a/pkg/services/object/search/query/v1/v1.go +++ b/pkg/services/object/search/query/v1/v1.go @@ -4,6 +4,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/container" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/owner" + v2object "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/services/object/search/query" ) @@ -42,11 +43,11 @@ func (q *Query) Match(obj *object.Object, handler func(*objectSDK.ID)) { switch key := q.filters[i].Header(); key { default: match = headerEqual(obj, key, q.filters[i].Value()) - case objectSDK.KeyRoot: - match = (q.filters[i].Value() == objectSDK.ValRoot) == (!obj.HasParent() && + case v2object.FilterPropertyRoot: + match = (q.filters[i].Value() == v2object.BooleanPropertyValueTrue) == (!obj.HasParent() && obj.GetType() == objectSDK.TypeRegular) - case objectSDK.KeyLeaf: - match = (q.filters[i].Value() == objectSDK.ValLeaf) == (par == nil) + case v2object.FilterPropertyLeaf: + match = (q.filters[i].Value() == v2object.BooleanPropertyValueTrue) == (par == nil) } } } @@ -67,18 +68,14 @@ func headerEqual(obj *object.Object, key, value string) bool { } return false - case objectSDK.HdrSysNameID: - return value == idValue(obj.GetID()) - case objectSDK.HdrSysNameCID: + case v2object.FilterHeaderContainerID: return value == cidValue(obj.GetContainerID()) - case objectSDK.HdrSysNameOwnerID: + case v2object.FilterHeaderOwnerID: return value == ownerIDValue(obj.GetOwnerID()) - case keyNoChildrenField: - return len(obj.GetChildren()) == 0 - case keyParentIDField: + case v2object.FilterPropertyChildfree: + return (value == v2object.BooleanPropertyValueTrue) == (len(obj.GetChildren()) == 0) + case v2object.FilterHeaderParent: return idValue(obj.GetParentID()) == value - case keyParentField: - return len(obj.GetChildren()) > 0 // TODO: add other headers } } diff --git a/pkg/services/object/search/query/v1/v1_test.go b/pkg/services/object/search/query/v1/v1_test.go index 771b10d74f..ab3c4d5f20 100644 --- a/pkg/services/object/search/query/v1/v1_test.go +++ b/pkg/services/object/search/query/v1/v1_test.go @@ -58,24 +58,6 @@ func matchesQuery(q query.Query, obj *object.Object) (res bool) { } func TestQ_Match(t *testing.T) { - t.Run("object identifier equal", func(t *testing.T) { - obj := object.NewRaw() - - id := testID(t) - obj.SetID(id) - - fs := objectSDK.SearchFilters{} - fs.AddFilter(objectSDK.HdrSysNameID, idValue(id), objectSDK.MatchStringEqual) - - q := New(fs) - - require.True(t, matchesQuery(q, obj.Object())) - - obj.SetID(testID(t)) - - require.False(t, matchesQuery(q, obj.Object())) - }) - t.Run("container identifier equal", func(t *testing.T) { obj := object.NewRaw() @@ -83,7 +65,7 @@ func TestQ_Match(t *testing.T) { obj.SetContainerID(id) fs := objectSDK.SearchFilters{} - fs.AddFilter(objectSDK.HdrSysNameCID, cidValue(id), objectSDK.MatchStringEqual) + fs.AddObjectContainerIDFilter(objectSDK.MatchStringEqual, id) q := New(fs) @@ -101,7 +83,7 @@ func TestQ_Match(t *testing.T) { obj.SetOwnerID(id) fs := objectSDK.SearchFilters{} - fs.AddFilter(objectSDK.HdrSysNameOwnerID, ownerIDValue(id), objectSDK.MatchStringEqual) + fs.AddObjectOwnerIDFilter(objectSDK.MatchStringEqual, id) q := New(fs)