diff --git a/extensions/search/pkg/search/index/index.go b/extensions/search/pkg/search/index/index.go index f61c9e2a39..ca550647f0 100644 --- a/extensions/search/pkg/search/index/index.go +++ b/extensions/search/pkg/search/index/index.go @@ -34,9 +34,10 @@ import ( ) type indexDocument struct { - RootID string - Path string - ID string + RootID string + Path string + ID string + ParentID string Name string Size uint64 @@ -121,6 +122,7 @@ func toEntity(ref *sprovider.Reference, ri *sprovider.ResourceInfo) *indexDocume RootID: idToBleveId(ref.ResourceId), Path: ref.Path, ID: idToBleveId(ri.Id), + ParentID: idToBleveId(ri.ParentId), Name: ri.Path, Size: ri.Size, MimeType: ri.MimeType, @@ -159,10 +161,20 @@ func fromFields(fields map[string]interface{}) (*searchmsg.Match, error) { if mtime, err := time.Parse(time.RFC3339, fields["Mtime"].(string)); err == nil { match.Entity.LastModifiedTime = ×tamppb.Timestamp{Seconds: mtime.Unix(), Nanos: int32(mtime.Nanosecond())} } + if fields["ParentID"] != "" { + parentIDParts := strings.SplitN(fields["ParentID"].(string), "!", 2) + match.Entity.ParentId = &searchmsg.ResourceID{ + StorageId: parentIDParts[0], + OpaqueId: parentIDParts[1], + } + } return match, nil } func idToBleveId(id *sprovider.ResourceId) string { + if id == nil { + return "" + } return id.StorageId + "!" + id.OpaqueId } diff --git a/extensions/search/pkg/search/index/index_test.go b/extensions/search/pkg/search/index/index_test.go index 98ae27dd17..333a949264 100644 --- a/extensions/search/pkg/search/index/index_test.go +++ b/extensions/search/pkg/search/index/index_test.go @@ -44,6 +44,10 @@ var _ = Describe("Index", func() { StorageId: "storageid", OpaqueId: "opaqueid", }, + ParentId: &sprovider.ResourceId{ + StorageId: "storageid", + OpaqueId: "parentopaqueid", + }, Path: "foo.pdf", Size: 12345, MimeType: "application/pdf", @@ -124,6 +128,7 @@ var _ = Describe("Index", func() { Expect(match.Entity.Name).To(Equal(ri.Path)) Expect(match.Entity.Size).To(Equal(ri.Size)) Expect(match.Entity.MimeType).To(Equal(ri.MimeType)) + Expect(match.Entity.ParentId.OpaqueId).To(Equal(ri.ParentId.OpaqueId)) Expect(uint64(match.Entity.LastModifiedTime.AsTime().Unix())).To(Equal(ri.Mtime.Seconds)) })