Skip to content

Commit 7ce4dbe

Browse files
committed
feat(search): index and expose the video facet
1 parent cc2aa18 commit 7ce4dbe

14 files changed

Lines changed: 520 additions & 86 deletions

File tree

protogen/gen/opencloud/messages/search/v0/search.pb.go

Lines changed: 265 additions & 86 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protogen/gen/opencloud/messages/search/v0/search.pb.web.go

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protogen/gen/opencloud/services/search/v0/search.swagger.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@
298298
"items": {
299299
"type": "string"
300300
}
301+
},
302+
"video": {
303+
"$ref": "#/definitions/v0Video"
301304
}
302305
}
303306
},
@@ -531,6 +534,49 @@
531534
"format": "int32"
532535
}
533536
}
537+
},
538+
"v0Video": {
539+
"type": "object",
540+
"properties": {
541+
"audioBitsPerSample": {
542+
"type": "integer",
543+
"format": "int32"
544+
},
545+
"audioChannels": {
546+
"type": "integer",
547+
"format": "int32"
548+
},
549+
"audioFormat": {
550+
"type": "string"
551+
},
552+
"audioSamplesPerSecond": {
553+
"type": "integer",
554+
"format": "int32"
555+
},
556+
"bitrate": {
557+
"type": "integer",
558+
"format": "int32"
559+
},
560+
"duration": {
561+
"type": "string",
562+
"format": "int64"
563+
},
564+
"fourCC": {
565+
"type": "string"
566+
},
567+
"frameRate": {
568+
"type": "number",
569+
"format": "double"
570+
},
571+
"height": {
572+
"type": "integer",
573+
"format": "int32"
574+
},
575+
"width": {
576+
"type": "integer",
577+
"format": "int32"
578+
}
579+
}
534580
}
535581
},
536582
"externalDocs": {

protogen/proto/opencloud/messages/search/v0/search.proto

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ message Photo {
5959
optional google.protobuf.Timestamp takenDateTime = 9;
6060
}
6161

62+
message Video {
63+
optional int32 audioBitsPerSample = 1;
64+
optional int32 audioChannels = 2;
65+
optional string audioFormat = 3;
66+
optional int32 audioSamplesPerSecond = 4;
67+
optional int32 bitrate = 5;
68+
optional int64 duration = 6;
69+
optional string fourCC = 7;
70+
optional double frameRate = 8;
71+
optional int32 height = 9;
72+
optional int32 width = 10;
73+
}
74+
6275
message Entity {
6376
Reference ref = 1;
6477
ResourceID id = 2;
@@ -80,6 +93,7 @@ message Entity {
8093
Image image = 18;
8194
Photo photo = 19;
8295
repeated string favorites = 20;
96+
Video video = 22;
8397
}
8498

8599
message Match {

services/graph/pkg/service/v0/driveitems.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ func cs3ResourceToDriveItem(logger *log.Logger, publicBaseURL *url.URL, res *sto
456456
driveItem.Image = metadataToFacet[libregraph.Image](metadata, "image")
457457
driveItem.Location = metadataToFacet[libregraph.GeoCoordinates](metadata, "location")
458458
driveItem.Photo = metadataToFacet[libregraph.Photo](metadata, "photo")
459+
driveItem.Video = metadataToFacet[libregraph.Video](metadata, "video")
459460
}
460461

461462
return driveItem, nil

services/search/pkg/bleve/backend.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ func (b *Backend) Search(_ context.Context, sir *searchService.SearchIndexReques
139139
Image: hitToFacet[searchMessage.Image](hit.Fields, "image"),
140140
Location: hitToFacet[searchMessage.GeoCoordinates](hit.Fields, "location"),
141141
Photo: hitToFacet[searchMessage.Photo](hit.Fields, "photo"),
142+
Video: hitToFacet[searchMessage.Video](hit.Fields, "video"),
142143
},
143144
}
144145

services/search/pkg/content/content.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Document struct {
2727
Image *libregraph.Image `json:"image,omitempty"`
2828
Location *libregraph.GeoCoordinates `json:"location,omitempty"`
2929
Photo *libregraph.Photo `json:"photo,omitempty"`
30+
Video *libregraph.Video `json:"video,omitempty"`
3031
}
3132

3233
func CleanString(content, langCode string) string {

services/search/pkg/content/tika.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ func (t Tika) Extract(ctx context.Context, ri *provider.ResourceInfo) (Document,
108108
if v := t.getAudio(meta); v != nil {
109109
doc.Audio = v
110110
}
111+
if v := t.getVideo(meta); v != nil {
112+
doc.Video = v
113+
}
111114
}
112115

113116
if langCode, _ := t.tika.LanguageString(ctx, doc.Content); langCode != "" && t.CleanStopWords {

services/search/pkg/content/tika_image.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@ package content
22

33
import (
44
"strconv"
5+
"strings"
56

67
libregraph "github.com/opencloud-eu/libre-graph-api-go"
78
)
89

910
func (t Tika) getImage(meta map[string][]string) *libregraph.Image {
11+
// tiff:ImageWidth/Length are also set for videos; the content type is what
12+
// tells an image apart.
13+
if ct, err := getFirstValue(meta, "Content-Type"); err != nil || !strings.HasPrefix(ct, "image/") {
14+
return nil
15+
}
16+
1017
var image *libregraph.Image
1118
initImage := func() {
1219
if image == nil {

services/search/pkg/content/tika_image_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
var _ = Describe("getImage", func() {
1010
It("maps the image dimensions to the image facet", func() {
1111
image := Tika{}.getImage(map[string][]string{
12+
"Content-Type": {"image/jpeg"},
1213
"tiff:ImageWidth": {"100"},
1314
"tiff:ImageLength": {"200"},
1415
})
@@ -17,6 +18,14 @@ var _ = Describe("getImage", func() {
1718
Expect(image.Height).To(Equal(libregraph.PtrInt32(200)))
1819
})
1920

21+
It("returns nil for a video even though it carries the same tiff dimensions", func() {
22+
Expect(Tika{}.getImage(map[string][]string{
23+
"Content-Type": {"video/mp4"},
24+
"tiff:ImageWidth": {"1920"},
25+
"tiff:ImageLength": {"1080"},
26+
})).To(BeNil())
27+
})
28+
2029
It("returns nil when no image metadata is present", func() {
2130
Expect(Tika{}.getImage(map[string][]string{})).To(BeNil())
2231
})

0 commit comments

Comments
 (0)