fix(search): type mtime as a date

This commit is contained in:
Dominik Schmidt committed 2026-08-18 17:12:32 +02:00
1 parent 14bcd45d4d
commit 102f2274a3
7 files changed
+20 -16

No files matched your search

+5 -1
View File
@@ -1,6 +1,10 @@
package bleve_test
import (
"time"
"github.com/opencloud-eu/opencloud/pkg/conversions"
bleveSearch "github.com/blevesearch/bleve/v2"
bquery "github.com/blevesearch/bleve/v2/search/query"
. "github.com/onsi/ginkgo/v2"
@@ -21,7 +25,7 @@ var _ = Describe("Mtime date range", func() {
idx, err := bleveSearch.NewMemOnly(m)
Expect(err).ToNot(HaveOccurred())
r := search.Resource{ID: "x", Document: content.Document{Name: "f", Mtime: "2026-03-15T12:00:00.123456789Z"}}
r := search.Resource{ID: "x", Document: content.Document{Name: "f", Mtime: conversions.ToPointer(time.Date(2026, 3, 15, 12, 0, 0, 123456789, time.UTC))}}
doc, err := mapping.PrepareForIndex(r, r.SearchFieldOverrides())
Expect(err).ToNot(HaveOccurred())
Expect(idx.Index(r.ID, doc)).To(Succeed())
+2 -2
View File
@@ -3,9 +3,9 @@ package content
import (
"context"
"encoding/json"
"time"
storageProvider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/opencloud-eu/opencloud/pkg/conversions"
"github.com/opencloud-eu/opencloud/pkg/log"
"github.com/opencloud-eu/reva/v2/pkg/tags"
"github.com/opencloud-eu/reva/v2/pkg/utils"
@@ -54,7 +54,7 @@ func (b Basic) Extract(_ context.Context, ri *storageProvider.ResourceInfo) (Doc
}
if ri.Mtime != nil {
doc.Mtime = utils.TSToTime(ri.Mtime).UTC().Format(time.RFC3339Nano)
doc.Mtime = conversions.ToPointer(utils.TSToTime(ri.Mtime).UTC())
}
return doc, nil
+8 -4
View File
@@ -1,6 +1,10 @@
package content_test
import (
"time"
"github.com/opencloud-eu/opencloud/pkg/conversions"
"context"
"encoding/json"
@@ -69,11 +73,11 @@ var _ = Describe("Basic", func() {
It("RFC3339 mtime", func() {
for _, data := range []struct {
second uint64
expect string
expect *time.Time
}{
{second: 4000, expect: "1970-01-01T01:06:40Z"},
{second: 3000, expect: "1970-01-01T00:50:00Z"},
{expect: ""},
{second: 4000, expect: conversions.ToPointer(time.Unix(4000, 0).UTC())},
{second: 3000, expect: conversions.ToPointer(time.Unix(3000, 0).UTC())},
{},
} {
ri := &storageProvider.ResourceInfo{}
+2 -1
View File
@@ -2,6 +2,7 @@ package content
import (
"strings"
"time"
"github.com/bbalet/stopwords"
libregraph "github.com/opencloud-eu/libre-graph-api-go"
@@ -18,7 +19,7 @@ type Document struct {
Name string `json:"Name"`
Content string `json:"Content"`
Size uint64 `json:"Size"`
Mtime string `json:"Mtime"`
Mtime *time.Time `json:"Mtime"`
MimeType string `json:"MimeType"`
Tags []string `json:"Tags"`
Favorites []string `json:"Favorites"`
@@ -3,7 +3,6 @@ package convert
import (
"fmt"
"strings"
"time"
opensearchgoAPI "github.com/opensearch-project/opensearch-go/v4/opensearchapi"
"google.golang.org/protobuf/types/known/timestamppb"
@@ -87,8 +86,8 @@ func OpenSearchHitToMatch(hit opensearchgoAPI.SearchHit) (*searchMessage.Match,
},
}
if mtime, err := time.Parse(time.RFC3339, resource.Mtime); err == nil {
match.Entity.LastModifiedTime = &timestamppb.Timestamp{Seconds: mtime.Unix(), Nanos: int32(mtime.Nanosecond())}
if resource.Mtime != nil {
match.Entity.LastModifiedTime = timestamppb.New(*resource.Mtime)
}
return match, nil
@@ -36,7 +36,7 @@ var _ = Describe("OpenSearchHitToMatch", func() {
resource = opensearchtest.Testdata.Resources.File
resource.MimeType = "audio/mpeg"
mtime = time.Date(2025, 7, 24, 15, 15, 1, 0, time.UTC)
resource.Mtime = mtime.Format(time.RFC3339)
resource.Mtime = &mtime
resource.Favorites = []string{"cbf24bce-3e6e-4d9e-a2a2-cbf24bce3e6e"}
hit = opensearchgoAPI.SearchHit{
-4
View File
@@ -72,10 +72,6 @@ var resourceFieldOverrides = sync.OnceValue(func() map[string]mapping.FieldOpts
"Tags": {Analyzer: "lowercaseKeyword", IncludeInAll: &excludeFromAll},
"Favorites": {Analyzer: "lowercaseKeyword", IncludeInAll: &excludeFromAll},
"location": {Type: mapping.TypeGeopoint},
// Mtime is stored as an RFC3339 string; type it as a date so mtime:>...
// range queries are chronological on both backends (bleve DateRangeQuery
// / OpenSearch date range), not a lexicographic keyword compare.
"Mtime": {Type: mapping.TypeDatetime},
}
})