diff --git a/go.mod b/go.mod index 8de48018e6e..0e1217415af 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/blevesearch/bleve/v2 v2.3.3 github.com/coreos/go-oidc/v3 v3.2.0 github.com/cs3org/go-cs3apis v0.0.0-20220719130120-361e9f987d64 - github.com/cs3org/reva/v2 v2.7.3-0.20220809114111-4f5f5aa9a1e0 + github.com/cs3org/reva/v2 v2.7.3-0.20220810074418-45c42bf59913 github.com/disintegration/imaging v1.6.2 github.com/ggwhite/go-masker v1.0.9 github.com/go-chi/chi/v5 v5.0.7 diff --git a/go.sum b/go.sum index 2d2c312056d..4d1570824f0 100644 --- a/go.sum +++ b/go.sum @@ -290,8 +290,8 @@ github.com/crewjam/saml v0.4.6 h1:XCUFPkQSJLvzyl4cW9OvpWUbRf0gE7VUpU8ZnilbeM4= github.com/crewjam/saml v0.4.6/go.mod h1:ZBOXnNPFzB3CgOkRm7Nd6IVdkG+l/wF+0ZXLqD96t1A= github.com/cs3org/go-cs3apis v0.0.0-20220719130120-361e9f987d64 h1:cFnankJOCWndnOns4sKRG7yzH61ammK2Am6rEGWCK40= github.com/cs3org/go-cs3apis v0.0.0-20220719130120-361e9f987d64/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY= -github.com/cs3org/reva/v2 v2.7.3-0.20220809114111-4f5f5aa9a1e0 h1:Gwgs/8K/1974ZMW/vajCbh7uPjqTR/jwPRZRKks9u/4= -github.com/cs3org/reva/v2 v2.7.3-0.20220809114111-4f5f5aa9a1e0/go.mod h1:2TY/LuIbnzpIqbL0J7AtVAaVOGw30zuZkWsPIPbW1pU= +github.com/cs3org/reva/v2 v2.7.3-0.20220810074418-45c42bf59913 h1:/Pzp2PJTz3D0trTfx32OgyPSr5kUhUm3+kuapOVVeys= +github.com/cs3org/reva/v2 v2.7.3-0.20220810074418-45c42bf59913/go.mod h1:2TY/LuIbnzpIqbL0J7AtVAaVOGw30zuZkWsPIPbW1pU= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI= github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= diff --git a/protogen/gen/ocis/messages/search/v0/search.pb.go b/protogen/gen/ocis/messages/search/v0/search.pb.go index d50cb7c38ec..36f32d7f41c 100644 --- a/protogen/gen/ocis/messages/search/v0/search.pb.go +++ b/protogen/gen/ocis/messages/search/v0/search.pb.go @@ -154,6 +154,7 @@ type Entity struct { Permissions string `protobuf:"bytes,8,opt,name=permissions,proto3" json:"permissions,omitempty"` Type uint64 `protobuf:"varint,9,opt,name=type,proto3" json:"type,omitempty"` Deleted bool `protobuf:"varint,10,opt,name=deleted,proto3" json:"deleted,omitempty"` + Tags []string `protobuf:"bytes,11,rep,name=tags,proto3" json:"tags,omitempty"` } func (x *Entity) Reset() { @@ -258,6 +259,13 @@ func (x *Entity) GetDeleted() bool { return false } +func (x *Entity) GetTags() []string { + if x != nil { + return x.Tags + } + return nil +} + type Match struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -336,7 +344,7 @@ var file_ocis_messages_search_v0_search_proto_rawDesc = []byte{ 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x2e, 0x76, 0x30, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x49, 0x44, 0x52, 0x0a, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x22, 0xe6, 0x02, 0x0a, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x22, 0xfa, 0x02, 0x0a, 0x06, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x34, 0x0a, 0x03, 0x72, 0x65, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x6f, 0x63, 0x69, 0x73, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x2e, 0x76, 0x30, 0x2e, 0x52, @@ -359,17 +367,18 @@ var file_ocis_messages_search_v0_search_proto_rawDesc = []byte{ 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x04, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x64, 0x65, - 0x6c, 0x65, 0x74, 0x65, 0x64, 0x22, 0x56, 0x0a, 0x05, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x12, 0x37, - 0x0a, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1f, - 0x2e, 0x6f, 0x63, 0x69, 0x73, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x73, - 0x65, 0x61, 0x72, 0x63, 0x68, 0x2e, 0x76, 0x30, 0x2e, 0x45, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, - 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x02, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x42, 0x42, 0x5a, - 0x40, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x77, 0x6e, 0x63, - 0x6c, 0x6f, 0x75, 0x64, 0x2f, 0x6f, 0x63, 0x69, 0x73, 0x2f, 0x76, 0x32, 0x2f, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x67, 0x65, 0x6e, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x6f, 0x63, 0x69, 0x73, 0x2f, 0x6d, - 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2f, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x2f, 0x76, - 0x30, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6c, 0x65, 0x74, 0x65, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x61, 0x67, 0x73, 0x18, 0x0b, 0x20, + 0x03, 0x28, 0x09, 0x52, 0x04, 0x74, 0x61, 0x67, 0x73, 0x22, 0x56, 0x0a, 0x05, 0x4d, 0x61, 0x74, + 0x63, 0x68, 0x12, 0x37, 0x0a, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x6f, 0x63, 0x69, 0x73, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, + 0x65, 0x73, 0x2e, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x2e, 0x76, 0x30, 0x2e, 0x45, 0x6e, 0x74, + 0x69, 0x74, 0x79, 0x52, 0x06, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x73, + 0x63, 0x6f, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x02, 0x52, 0x05, 0x73, 0x63, 0x6f, 0x72, + 0x65, 0x42, 0x42, 0x5a, 0x40, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x6f, 0x77, 0x6e, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x2f, 0x6f, 0x63, 0x69, 0x73, 0x2f, 0x76, 0x32, + 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x67, 0x65, 0x6e, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x6f, 0x63, + 0x69, 0x73, 0x2f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2f, 0x73, 0x65, 0x61, 0x72, + 0x63, 0x68, 0x2f, 0x76, 0x30, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/protogen/gen/ocis/services/search/v0/search.swagger.json b/protogen/gen/ocis/services/search/v0/search.swagger.json index 5d0f8bd4dd7..4201f601f40 100644 --- a/protogen/gen/ocis/services/search/v0/search.swagger.json +++ b/protogen/gen/ocis/services/search/v0/search.swagger.json @@ -192,6 +192,12 @@ }, "deleted": { "type": "boolean" + }, + "tags": { + "type": "array", + "items": { + "type": "string" + } } } }, diff --git a/protogen/gen/ocis/services/store/v0/store.pb.micro.go b/protogen/gen/ocis/services/store/v0/store.pb.micro.go index ed25b475640..53121345666 100644 --- a/protogen/gen/ocis/services/store/v0/store.pb.micro.go +++ b/protogen/gen/ocis/services/store/v0/store.pb.micro.go @@ -104,6 +104,7 @@ type Store_ListService interface { Context() context.Context SendMsg(interface{}) error RecvMsg(interface{}) error + CloseSend() error Close() error Recv() (*ListResponse, error) } @@ -112,6 +113,10 @@ type storeServiceList struct { stream client.Stream } +func (x *storeServiceList) CloseSend() error { + return x.stream.CloseSend() +} + func (x *storeServiceList) Close() error { return x.stream.Close() } diff --git a/protogen/proto/ocis/messages/search/v0/search.proto b/protogen/proto/ocis/messages/search/v0/search.proto index 3ece6a30800..878b292c988 100644 --- a/protogen/proto/ocis/messages/search/v0/search.proto +++ b/protogen/proto/ocis/messages/search/v0/search.proto @@ -7,32 +7,33 @@ import "google/protobuf/timestamp.proto"; option go_package = "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/search/v0"; message ResourceID { - string storage_id = 1; - string opaque_id = 2; - string space_id = 3; + string storage_id = 1; + string opaque_id = 2; + string space_id = 3; } message Reference { - ResourceID resource_id = 1; - string path = 2; + ResourceID resource_id = 1; + string path = 2; } message Entity { - Reference ref = 1; - ResourceID id = 2; - string name = 3; - string etag = 4; - uint64 size = 5; - google.protobuf.Timestamp last_modified_time = 6; - string mime_type = 7; - string permissions = 8; - uint64 type = 9; - bool deleted = 10; + Reference ref = 1; + ResourceID id = 2; + string name = 3; + string etag = 4; + uint64 size = 5; + google.protobuf.Timestamp last_modified_time = 6; + string mime_type = 7; + string permissions = 8; + uint64 type = 9; + bool deleted = 10; + repeated string tags = 11; } message Match { - // the matched entity - Entity entity = 1; - // the match score - float score = 2; + // the matched entity + Entity entity = 1; + // the match score + float score = 2; } diff --git a/services/search/pkg/content/basic.go b/services/search/pkg/content/basic.go index 7681e9b98fa..d507255baca 100644 --- a/services/search/pkg/content/basic.go +++ b/services/search/pkg/content/basic.go @@ -3,8 +3,8 @@ package content import ( "context" storageProvider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + "github.com/cs3org/reva/v2/pkg/tags" "github.com/owncloud/ocis/v2/ocis-pkg/log" - "strings" "time" ) @@ -19,20 +19,16 @@ func NewBasicExtractor(logger log.Logger) (*Basic, error) { } // Extract literally just rearranges the inputs and processes them into a Document. -func (b Basic) Extract(ctx context.Context, ri *storageProvider.ResourceInfo) (Document, error) { +func (b Basic) Extract(_ context.Context, ri *storageProvider.ResourceInfo) (Document, error) { doc := Document{ Name: ri.Path, Size: ri.Size, MimeType: ri.MimeType, } - if ri.ArbitraryMetadata != nil && ri.ArbitraryMetadata.Metadata != nil { - if tags, ok := ri.ArbitraryMetadata.Metadata["tags"]; ok { - doc.Tags = strings.FieldsFunc(tags, func(r rune) bool { return r == ',' }) - - for i, t := range doc.Tags { - doc.Tags[i] = strings.TrimSpace(t) - } + if m := ri.ArbitraryMetadata.GetMetadata(); m != nil { + if t, ok := m["tags"]; ok { + doc.Tags = tags.FromList(t).AsSlice() } } diff --git a/services/search/pkg/content/basic_test.go b/services/search/pkg/content/basic_test.go index e5f0a2afe98..5c08f53218f 100644 --- a/services/search/pkg/content/basic_test.go +++ b/services/search/pkg/content/basic_test.go @@ -46,7 +46,7 @@ var _ = Describe("Basic", func() { {tags: "", expect: []string{}}, {tags: ",,,", expect: []string{}}, {tags: ",foo,,", expect: []string{"foo"}}, - {tags: ",foo,,bar, baz, a,,b,, start and end space ,,", expect: []string{"foo", "bar", "baz", "a", "b", "start and end space"}}, + {tags: ",foo,,bar,", expect: []string{"foo", "bar"}}, } { ri := &storageProvider.ResourceInfo{ ArbitraryMetadata: &storageProvider.ArbitraryMetadata{ diff --git a/services/search/pkg/content/retriever.go b/services/search/pkg/content/retriever.go index c543c9ede52..149ccb4d2f1 100644 --- a/services/search/pkg/content/retriever.go +++ b/services/search/pkg/content/retriever.go @@ -21,7 +21,6 @@ func contextGet(ctx context.Context, k string) (string, bool) { } token, ok := md[k] - if len(token) == 0 || !ok { return "", false } diff --git a/services/search/pkg/content/tika.go b/services/search/pkg/content/tika.go index 7714b190281..53edf9a1495 100644 --- a/services/search/pkg/content/tika.go +++ b/services/search/pkg/content/tika.go @@ -64,8 +64,6 @@ func (t Tika) Extract(ctx context.Context, ri *provider.ResourceInfo) (Document, return doc, err } - fmt.Println(d1.String()) - lang, err := t.tika.Language(ctx, bytes.NewReader(d1.Bytes())) if err != nil { return doc, nil diff --git a/services/search/pkg/engine/bleve.go b/services/search/pkg/engine/bleve.go index d95403850e0..5fa49f850ce 100644 --- a/services/search/pkg/engine/bleve.go +++ b/services/search/pkg/engine/bleve.go @@ -86,7 +86,7 @@ func BuildBleveMapping() (mapping.IndexMapping, error) { // Search executes a search request operation within the index. // Returns a SearchIndexResponse object or an error. -func (b *Bleve) Search(ctx context.Context, sir *searchService.SearchIndexRequest) (*searchService.SearchIndexResponse, error) { +func (b *Bleve) Search(_ context.Context, sir *searchService.SearchIndexRequest) (*searchService.SearchIndexResponse, error) { q := bleve.NewConjunctionQuery( &query.QueryStringQuery{ Query: b.buildQuery(sir.Query), @@ -150,6 +150,7 @@ func (b *Bleve) Search(ctx context.Context, sir *searchService.SearchIndexReques Type: uint64(getValue[float64](hit.Fields, "Type")), MimeType: getValue[string](hit.Fields, "MimeType"), Deleted: getValue[bool](hit.Fields, "Deleted"), + Tags: getValue[[]string](hit.Fields, "Tags"), }, } diff --git a/services/search/pkg/engine/bleve_test.go b/services/search/pkg/engine/bleve_test.go index fce073e7eb0..4d0311d29c7 100644 --- a/services/search/pkg/engine/bleve_test.go +++ b/services/search/pkg/engine/bleve_test.go @@ -94,6 +94,25 @@ var _ = Describe("Bleve", func() { assertDocCount(rid, `Size:<1000`, 0) assertDocCount(rid, `Size:>100000`, 0) }) + + It("finds files by tags", func() { + rid := sprovider.ResourceId{ + StorageId: "1", + SpaceId: "2", + OpaqueId: "3", + } + r := createEntity(rid, content.Document{Tags: []string{"foo", "bar"}}) + err := eng.Upsert(r.ID, r) + Expect(err).ToNot(HaveOccurred()) + + assertDocCount(rid, `Tags:foo`, 1) + assertDocCount(rid, `Tags:bar`, 1) + assertDocCount(rid, `Tags:foo Tags:bar`, 1) + assertDocCount(rid, `Tags:foo Tags:bar Tags:baz`, 1) + assertDocCount(rid, `+Tags:foo +Tags:bar Tags:baz`, 1) + assertDocCount(rid, `+Tags:foo +Tags:bar +Tags:baz`, 0) + assertDocCount(rid, `Tags:baz`, 0) + }) }) Context("by filename", func() { diff --git a/services/search/pkg/engine/engine.go b/services/search/pkg/engine/engine.go index dd21265a37b..97184518dd3 100644 --- a/services/search/pkg/engine/engine.go +++ b/services/search/pkg/engine/engine.go @@ -6,7 +6,6 @@ import ( searchMessage "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/search/v0" searchSearvice "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/search/v0" "github.com/owncloud/ocis/v2/services/search/pkg/content" - "reflect" "regexp" ) @@ -47,34 +46,12 @@ func escapeQuery(s string) string { } func getValue[T any](m map[string]interface{}, key string) (out T) { - keyValue, ok := m[key] + val, ok := m[key] if !ok { return } - rk := reflect.TypeOf(out).Kind() + out, _ = val.(T) - if rk == reflect.Slice { - values, ok := keyValue.([]interface{}) - if !ok { - return - } - - slice := reflect.MakeSlice(reflect.TypeOf(out), 0, len(values)) - sliceOf := slice.Type().Elem() - - for _, val := range values { - if reflect.TypeOf(val) != sliceOf { - continue - } - - slice = reflect.Append(slice, reflect.ValueOf(val)) - } - - out, _ = slice.Interface().(T) - return - } - - out, _ = keyValue.(T) return } diff --git a/services/search/pkg/search/search.go b/services/search/pkg/search/search.go index 8f668e0a74e..40b8474cd9f 100644 --- a/services/search/pkg/search/search.go +++ b/services/search/pkg/search/search.go @@ -2,6 +2,7 @@ package search import ( "context" + "errors" gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" @@ -61,7 +62,8 @@ func statResource(ctx context.Context, ref *provider.Reference, gw gateway.Gatew return nil, err } if res.Status.Code != rpc.Code_CODE_OK { - logger.Error().Interface("res", res).Msg("failed to stat the moved resource") + err := errors.New("failed to stat the moved resource") + logger.Error().Interface("res", res).Msg(err.Error()) return nil, err } @@ -76,7 +78,9 @@ func getPath(ctx context.Context, id *provider.ResourceId, gw gateway.GatewayAPI return nil, err } if res.Status.Code != rpc.Code_CODE_OK { - logger.Error().Interface("status", res.Status).Interface("id", id).Msg("failed to get path for moved resource") + err := errors.New("failed to get path for moved resource") + + logger.Error().Interface("status", res.Status).Interface("id", id).Msg(err.Error()) return nil, err }