From fe48e3ab5b535c56302b909a539840340e874ef1 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 9 Nov 2020 15:41:40 +0300 Subject: [PATCH] [#191] pkg/object: Use `root` and `phy` filters as flags Inverted values for `root` and `phy` filters now are not supported. Therefore these filters works like flags. It either presented in search query or not. Signed-off-by: Alex Vanin --- pkg/object/search.go | 27 +++++++++++++-------------- pkg/object/search_test.go | 36 ++++-------------------------------- 2 files changed, 17 insertions(+), 46 deletions(-) diff --git a/pkg/object/search.go b/pkg/object/search.go index 2fdcd9e0..167f21fb 100644 --- a/pkg/object/search.go +++ b/pkg/object/search.go @@ -173,6 +173,13 @@ func (f *SearchFilters) addReservedFilter(op SearchMatchType, keyTyp filterKeyTy f.addFilter(op, keyTyp, "", val) } +// addFlagFilters adds filters that works like flags: they don't need to have +// specific match type or value. They processed by NeoFS nodes by the fact +// of presence in search query. E.g.: PHY, ROOT. +func (f *SearchFilters) addFlagFilter(keyTyp filterKeyType) { + f.addFilter(MatchUnknown, keyTyp, "", staticStringer("")) +} + func (f *SearchFilters) AddObjectVersionFilter(op SearchMatchType, v *pkg.Version) { f.addReservedFilter(op, fKeyVersion, v) } @@ -199,28 +206,20 @@ func (f SearchFilters) ToV2() []*v2object.SearchFilter { return result } -func (f *SearchFilters) addRootFilter(val bool) { - f.addReservedFilter(MatchStringEqual, fKeyPropRoot, boolStringer(val)) +func (f *SearchFilters) addRootFilter() { + f.addFlagFilter(fKeyPropRoot) } func (f *SearchFilters) AddRootFilter() { - f.addRootFilter(true) + f.addRootFilter() } -func (f *SearchFilters) AddNonRootFilter() { - f.addRootFilter(false) -} - -func (f *SearchFilters) addPhyFilter(val bool) { - f.addReservedFilter(MatchStringEqual, fKeyPropPhy, boolStringer(val)) +func (f *SearchFilters) addPhyFilter() { + f.addFlagFilter(fKeyPropPhy) } func (f *SearchFilters) AddPhyFilter() { - f.addPhyFilter(true) -} - -func (f *SearchFilters) AddNonPhyFilter() { - f.addPhyFilter(false) + f.addPhyFilter() } func (f *SearchFilters) addChildFreeFilter(val bool) { diff --git a/pkg/object/search_test.go b/pkg/object/search_test.go index f6caae72..ca28f1fe 100644 --- a/pkg/object/search_test.go +++ b/pkg/object/search_test.go @@ -62,23 +62,9 @@ func TestSearchFilters_AddRootFilter(t *testing.T) { f := (*fs)[0] - require.Equal(t, object.MatchStringEqual, f.Operation()) + require.Equal(t, object.MatchUnknown, f.Operation()) require.Equal(t, v2object.FilterPropertyRoot, f.Header()) - require.Equal(t, v2object.BooleanPropertyValueTrue, f.Value()) -} - -func TestSearchFilters_AddNonRootFilter(t *testing.T) { - fs := new(object.SearchFilters) - - fs.AddNonRootFilter() - - require.Len(t, *fs, 1) - - f := (*fs)[0] - - require.Equal(t, object.MatchStringEqual, f.Operation()) - require.Equal(t, v2object.FilterPropertyRoot, f.Header()) - require.Equal(t, v2object.BooleanPropertyValueFalse, f.Value()) + require.Equal(t, "", f.Value()) } func TestSearchFilters_AddPhyFilter(t *testing.T) { @@ -90,23 +76,9 @@ func TestSearchFilters_AddPhyFilter(t *testing.T) { f := (*fs)[0] - require.Equal(t, object.MatchStringEqual, f.Operation()) + require.Equal(t, object.MatchUnknown, f.Operation()) require.Equal(t, v2object.FilterPropertyPhy, f.Header()) - require.Equal(t, v2object.BooleanPropertyValueTrue, f.Value()) -} - -func TestSearchFilters_AddNonPhyFilter(t *testing.T) { - fs := new(object.SearchFilters) - - fs.AddNonPhyFilter() - - require.Len(t, *fs, 1) - - f := (*fs)[0] - - require.Equal(t, object.MatchStringEqual, f.Operation()) - require.Equal(t, v2object.FilterPropertyPhy, f.Header()) - require.Equal(t, v2object.BooleanPropertyValueFalse, f.Value()) + require.Equal(t, "", f.Value()) } func testOID() *object.ID {