mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-09 17:44:59 +09:00
Fix Not filter
This commit is contained in:
parent
fcb8a04196
commit
e7f83e0519
6 changed files with 67 additions and 1 deletions
2
go.mod
2
go.mod
|
@ -7,7 +7,7 @@ require (
|
|||
github.com/PuerkitoBio/goquery v1.9.2
|
||||
github.com/VividCortex/ewma v1.2.0
|
||||
github.com/adrium/goheif v0.0.0-20230113233934-ca402e77a786
|
||||
github.com/anyproto/any-store v0.0.1
|
||||
github.com/anyproto/any-store v0.0.2-0.20240812125400-7f6f6d062ebf
|
||||
github.com/anyproto/any-sync v0.4.22
|
||||
github.com/anyproto/go-naturaldate/v2 v2.0.2-0.20230524105841-9829cfd13438
|
||||
github.com/anyproto/tantivy-go v0.0.7
|
||||
|
|
2
go.sum
2
go.sum
|
@ -87,6 +87,8 @@ github.com/anyproto/any-store v0.0.0-20240719163025-8a3657f8e01c h1:rRlF97BLA+4/
|
|||
github.com/anyproto/any-store v0.0.0-20240719163025-8a3657f8e01c/go.mod h1:JV7dJ8+xF1VaCQgFQsD8SZSNlxxTGFbDiF8llkB2ILc=
|
||||
github.com/anyproto/any-store v0.0.1 h1:RiZi3cHVSpIebcNeHYOUaDShH7E9Ahto33zdnqCaUHM=
|
||||
github.com/anyproto/any-store v0.0.1/go.mod h1:JV7dJ8+xF1VaCQgFQsD8SZSNlxxTGFbDiF8llkB2ILc=
|
||||
github.com/anyproto/any-store v0.0.2-0.20240812125400-7f6f6d062ebf h1:9VTQc/011fVyucu9bICmjF6+y/T9QdZv6MN7X4gM4S0=
|
||||
github.com/anyproto/any-store v0.0.2-0.20240812125400-7f6f6d062ebf/go.mod h1:JV7dJ8+xF1VaCQgFQsD8SZSNlxxTGFbDiF8llkB2ILc=
|
||||
github.com/anyproto/any-sync v0.4.22 h1:f9iAbCv/clTzYtzOzkX1IOXahVM/Art1WkUtIgnwl8U=
|
||||
github.com/anyproto/any-sync v0.4.22/go.mod h1:qHIG2zMvGIthEb2FmcjQN5YZZwV8kPHv7/T0ib7YSDg=
|
||||
github.com/anyproto/badger/v4 v4.2.1-0.20240110160636-80743fa3d580 h1:Ba80IlCCxkZ9H1GF+7vFu/TSpPvbpDCxXJ5ogc4euYc=
|
||||
|
|
|
@ -275,6 +275,12 @@ func negateFilter(filter query.Filter) query.Filter {
|
|||
}
|
||||
return negated
|
||||
case query.Key:
|
||||
if nested, ok := v.Filter.(query.Not); ok {
|
||||
return query.Key{
|
||||
Path: v.Path,
|
||||
Filter: nested.Filter,
|
||||
}
|
||||
}
|
||||
return query.Key{
|
||||
Path: v.Path,
|
||||
Filter: query.Not{
|
||||
|
|
|
@ -124,6 +124,23 @@ func TestEq_FilterObject(t *testing.T) {
|
|||
obj = &types.Struct{Fields: map[string]*types.Value{"k": pbtypes.Float64(2)}}
|
||||
assertFilter(t, eq, obj, false)
|
||||
})
|
||||
|
||||
t.Run("not equal true: no key", func(t *testing.T) {
|
||||
eq := FilterEq{Key: "k", Value: pbtypes.Bool(true), Cond: model.BlockContentDataviewFilter_NotEqual}
|
||||
obj := &types.Struct{Fields: map[string]*types.Value{}}
|
||||
assertFilter(t, eq, obj, true)
|
||||
|
||||
obj = &types.Struct{Fields: map[string]*types.Value{"k": pbtypes.Bool(true)}}
|
||||
assertFilter(t, eq, obj, false)
|
||||
})
|
||||
t.Run("not equal false: no key", func(t *testing.T) {
|
||||
eq := FilterEq{Key: "k", Value: pbtypes.Bool(false), Cond: model.BlockContentDataviewFilter_NotEqual}
|
||||
obj := &types.Struct{Fields: map[string]*types.Value{}}
|
||||
assertFilter(t, eq, obj, true)
|
||||
|
||||
obj = &types.Struct{Fields: map[string]*types.Value{"k": pbtypes.Bool(false)}}
|
||||
assertFilter(t, eq, obj, false)
|
||||
})
|
||||
}
|
||||
|
||||
func TestNot_FilterObject(t *testing.T) {
|
||||
|
|
|
@ -273,6 +273,14 @@ func (s *dsObjectStore) runDatabase(ctx context.Context, path string) error {
|
|||
Name: "syncStatus",
|
||||
Fields: []string{bundle.RelationKeySyncStatus.String()},
|
||||
},
|
||||
{
|
||||
Name: "isDeleted",
|
||||
Fields: []string{bundle.RelationKeyIsDeleted.String()},
|
||||
},
|
||||
{
|
||||
Name: "isArchived",
|
||||
Fields: []string{bundle.RelationKeyIsArchived.String()},
|
||||
},
|
||||
}
|
||||
err = s.addIndexes(ctx, objects, objectIndexes)
|
||||
if err != nil {
|
||||
|
|
|
@ -1182,3 +1182,36 @@ func TestGetSpaceIDFromFilters(t *testing.T) {
|
|||
assert.Equal(t, []string{spaceId}, getSpaceIdsFromFilter(f))
|
||||
})
|
||||
}
|
||||
|
||||
func TestIndex(t *testing.T) {
|
||||
s := NewStoreFixture(t)
|
||||
obj1 := TestObject{
|
||||
bundle.RelationKeyId: pbtypes.String("id1"),
|
||||
bundle.RelationKeyName: pbtypes.String("name1"),
|
||||
bundle.RelationKeyIsDeleted: pbtypes.Bool(true),
|
||||
}
|
||||
obj2 := TestObject{
|
||||
bundle.RelationKeyId: pbtypes.String("id2"),
|
||||
bundle.RelationKeyName: pbtypes.String("name2"),
|
||||
}
|
||||
obj3 := TestObject{
|
||||
bundle.RelationKeyId: pbtypes.String("id3"),
|
||||
bundle.RelationKeyName: pbtypes.String("name3"),
|
||||
}
|
||||
s.AddObjects(t, []TestObject{obj1, obj2, obj3})
|
||||
|
||||
recs, err := s.Query(database.Query{
|
||||
Filters: []*model.BlockContentDataviewFilter{
|
||||
{
|
||||
RelationKey: bundle.RelationKeyIsDeleted.String(),
|
||||
Condition: model.BlockContentDataviewFilter_NotEqual,
|
||||
Value: pbtypes.Bool(true),
|
||||
},
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
assertRecordsEqual(t, []TestObject{
|
||||
obj2, obj3,
|
||||
}, recs)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue