mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-09-14 06:39:07 -04:00
SharePoint's default for a text property is word breaking, so ours is too: every keyword field gets the _words sibling unless it opts out with NoWordBreaker, which now carries SharePoint's polarity as well. Artist, album, camera model and the other facets match by word like name and title; tags and favorites stay one label, ids, paths and the mime type one value.
73 lines
2.0 KiB
Go
73 lines
2.0 KiB
Go
package mapping
|
|
|
|
import (
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("PrepareForIndex serialization", func() {
|
|
It("errors for a non-marshallable value", func() {
|
|
// a func field can't be json-marshalled -> conversions.To errors
|
|
type bad struct {
|
|
F func() `json:"f"`
|
|
}
|
|
_, err := PrepareForIndex(bad{}, nil)
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
|
|
It("returns nil map for a typed nil pointer", func() {
|
|
// a typed nil pointer marshals to null -> nil map, no error, no panic
|
|
out, err := PrepareForIndex((*struct{})(nil), nil)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(out).To(BeNil())
|
|
})
|
|
|
|
It("flattens embedded structs", func() {
|
|
type Inner struct {
|
|
Name string `json:"Name"`
|
|
Size uint64 `json:"Size"`
|
|
}
|
|
type outer struct {
|
|
Inner
|
|
ID string `json:"ID"`
|
|
}
|
|
m, err := PrepareForIndex(outer{Inner: Inner{Name: "a", Size: 7}, ID: "x"}, nil)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
// keywords carry their lowercase and words search siblings by default
|
|
want := map[string]any{
|
|
"Name": "a", "Name_lowercase": "a", "Name_words": "a",
|
|
"Size": float64(7),
|
|
"ID": "x", "ID_lowercase": "x", "ID_words": "x",
|
|
}
|
|
Expect(m).To(Equal(want))
|
|
})
|
|
|
|
It("omits nil fields tagged omitempty", func() {
|
|
type facet struct {
|
|
Artist string `json:"artist"`
|
|
}
|
|
type doc struct {
|
|
Name string `json:"Name"`
|
|
Audio *facet `json:"audio,omitempty"`
|
|
}
|
|
m, err := PrepareForIndex(doc{Name: "n"}, nil)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(m).ToNot(HaveKey("audio"))
|
|
Expect(m["Name"]).To(Equal("n"))
|
|
})
|
|
|
|
It("includes nested facets when set", func() {
|
|
type facet struct {
|
|
Artist string `json:"artist"`
|
|
}
|
|
type doc struct {
|
|
Audio *facet `json:"audio,omitempty"`
|
|
}
|
|
m, err := PrepareForIndex(doc{Audio: &facet{Artist: "A"}}, nil)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
nested, ok := m["audio"].(map[string]any)
|
|
Expect(ok).To(BeTrue(), "audio should be a nested map: %#v", m["audio"])
|
|
Expect(nested["artist"]).To(Equal("A"))
|
|
})
|
|
})
|