mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-03-18 23:47:05 -04:00
Store the parent id in the index to allow for handling directories
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user