[#125] object/search: Use latest search filter keys

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
remotes/KirillovDenis/release/v0.21.1
Leonard Lyubich 2020-10-29 17:57:07 +03:00 committed by Alex Vanin
parent f34ad9e730
commit 8d931b81a6
3 changed files with 17 additions and 43 deletions

View File

@ -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
}

View File

@ -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
}
}

View File

@ -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)