Store the parent id in the index to allow for handling directories

This commit is contained in:
André Duffeck
2022-04-28 10:10:01 +02:00
parent e5338dff55
commit 68c5e2366c
2 changed files with 20 additions and 3 deletions

View File

@@ -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 = &timestamppb.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
}

View File

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