mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-11-26 18:16:47 -05:00
fix(search): index failed extractions by name and retry them
This commit is contained in:
1 parent
6cfc198663
commit
23f890cd62
7 files changed
+85
-4
No files matched your search
@@ -30,6 +30,19 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"ExtractionFailed": {
|
||||
"enabled": true,
|
||||
"dynamic": true,
|
||||
"fields": [
|
||||
{
|
||||
"type": "boolean",
|
||||
"store": true,
|
||||
"index": true,
|
||||
"include_in_all": true,
|
||||
"docvalues": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"Favorites": {
|
||||
"enabled": true,
|
||||
"dynamic": true,
|
||||
|
||||
@@ -86,6 +86,17 @@ func (t Tika) Extract(ctx context.Context, ri *provider.ResourceInfo) (Document,
|
||||
if len(metas) == 0 {
|
||||
return doc, fmt.Errorf("tika returned no metadata for %q", ri.GetName())
|
||||
}
|
||||
// tika answers a failed parse (ocr crash, broken pdf) with 200 and empty
|
||||
// content, only this key tells it apart from a file without text
|
||||
cause, err := getFirstValue(metas[0],
|
||||
"tk:exception:container-exception", // tika 4
|
||||
"X-TIKA:EXCEPTION:container_exception", // tika 3 legacy
|
||||
)
|
||||
if err == nil {
|
||||
// the value is a java stack trace, its first line names the cause
|
||||
cause, _, _ = strings.Cut(cause, "\n")
|
||||
return doc, fmt.Errorf("tika failed to parse %q: %s", ri.GetName(), cause)
|
||||
}
|
||||
|
||||
for _, meta := range metas {
|
||||
title, err := getFirstValue(meta, "dc:title")
|
||||
|
||||
@@ -110,6 +110,23 @@ var _ = Describe("Tika", func() {
|
||||
Expect(err).To(MatchError(ContainSubstring("report.pdf")))
|
||||
})
|
||||
|
||||
DescribeTable("fails when tika could not parse the file",
|
||||
func(response string) {
|
||||
fullResponse = response
|
||||
|
||||
doc, err := tika.Extract(context.TODO(), &provider.ResourceInfo{
|
||||
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
|
||||
Name: "scan.png",
|
||||
Size: 1,
|
||||
})
|
||||
Expect(err).To(MatchError(And(ContainSubstring("scan.png"), ContainSubstring("bad exit value 1"))))
|
||||
Expect(err.Error()).ToNot(ContainSubstring("at org.apache"))
|
||||
Expect(doc.Name).To(Equal("scan.png"))
|
||||
},
|
||||
Entry("tika 4", `[{"tk:content": "", "tk:exception:container-exception": "org.apache.tika.exception.TikaException: TesseractOCRParser bad exit value 1\n\tat org.apache.tika.parser.ocr.TesseractOCRParser.doOCR"}]`),
|
||||
Entry("tika 3", `[{"X-TIKA:content": "", "X-TIKA:EXCEPTION:container_exception": "org.apache.tika.exception.TikaException: TesseractOCRParser bad exit value 1\n\tat org.apache.tika.parser.ocr.TesseractOCRParser.doOCR"}]`),
|
||||
)
|
||||
|
||||
It("adds the title", func() {
|
||||
fullResponse = `[{"dc:title": "quarterly report", "X-TIKA:content": "some data"}]`
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
"Deleted": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"ExtractionFailed": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"Favorites": {
|
||||
"type": "keyword"
|
||||
},
|
||||
|
||||
@@ -85,6 +85,9 @@ type Resource struct {
|
||||
Type uint64 `json:"Type"`
|
||||
Deleted bool `json:"Deleted"`
|
||||
Hidden bool `json:"Hidden"`
|
||||
// ExtractionFailed marks a document indexed without its content, the next
|
||||
// reindex extracts it again; entries from before the field count as extracted
|
||||
ExtractionFailed bool `json:"ExtractionFailed"`
|
||||
}
|
||||
|
||||
// resourceFieldOverrides is built once (it never changes) and reused on hot
|
||||
|
||||
@@ -730,10 +730,12 @@ func (s *Service) doUpsertItem(ctx context.Context, ref *provider.Reference, bat
|
||||
return
|
||||
}
|
||||
|
||||
// a failed extraction still yields the name, path and tags, the resource
|
||||
// stays findable and the next space walk retries it
|
||||
doc, err := s.extractor.Extract(ctx, stat.Info)
|
||||
extractionFailed := err != nil
|
||||
if err != nil {
|
||||
s.logger.Error().Err(err).Msg("failed to extract resource content")
|
||||
return
|
||||
s.logger.Error().Err(err).Str("path", path).Msg("failed to extract resource content")
|
||||
}
|
||||
|
||||
r := Resource{
|
||||
@@ -748,6 +750,7 @@ func (s *Service) doUpsertItem(ctx context.Context, ref *provider.Reference, bat
|
||||
Document: doc,
|
||||
}
|
||||
r.Hidden = IsHidden(r.Path)
|
||||
r.ExtractionFailed = extractionFailed
|
||||
|
||||
if parentID := stat.GetInfo().GetParentId(); parentID != nil {
|
||||
r.ParentID = storagespace.FormatResourceID(parentID)
|
||||
@@ -764,6 +767,11 @@ func (s *Service) doUpsertItem(ctx context.Context, ref *provider.Reference, bat
|
||||
logDocCount(s.engine, s.logger)
|
||||
}
|
||||
|
||||
// without an extraction the facets are unknown, not gone
|
||||
if extractionFailed {
|
||||
return
|
||||
}
|
||||
|
||||
// determine if metadata needs to be stored in storage as well
|
||||
metadata := map[string]string{}
|
||||
facetToMetadata(metadata, doc.Audio, facetKeyPrefix+"audio.")
|
||||
@@ -943,7 +951,7 @@ func (s *Service) isIndexed(ctx context.Context, info *provider.ResourceInfo) bo
|
||||
s.logger.Error().Err(err).Interface("id", info.GetId()).Msg("failed to look up the indexed resource, indexing it again")
|
||||
return false
|
||||
}
|
||||
return !r.Deleted && r.Mtime != nil && !r.Mtime.Before(utils.TSToTime(info.GetMtime()))
|
||||
return !r.Deleted && !r.ExtractionFailed && r.Mtime != nil && !r.Mtime.Before(utils.TSToTime(info.GetMtime()))
|
||||
}
|
||||
|
||||
func (s *Service) resInfo(ctx context.Context, ref *provider.Reference) (*provider.StatResponse, string) {
|
||||
|
||||
@@ -158,12 +158,14 @@ var _ = Describe("Searchprovider", func() {
|
||||
info("outdated", sprovider.ResourceType_RESOURCE_TYPE_FILE, 5000),
|
||||
info("missing", sprovider.ResourceType_RESOURCE_TYPE_FILE, 4000),
|
||||
info("trashed", sprovider.ResourceType_RESOURCE_TYPE_FILE, 4000),
|
||||
info("failed", sprovider.ResourceType_RESOURCE_TYPE_FILE, 4000),
|
||||
}
|
||||
indexed := map[string]*search.Resource{
|
||||
"storageid$spaceid!spaceid": {Document: content.Document{Mtime: &indexedAt}},
|
||||
"storageid$spaceid!current": {Document: content.Document{Mtime: &indexedAt}},
|
||||
"storageid$spaceid!outdated": {Document: content.Document{Mtime: &indexedAt}},
|
||||
"storageid$spaceid!trashed": {Document: content.Document{Mtime: &indexedAt}, Deleted: true},
|
||||
"storageid$spaceid!failed": {Document: content.Document{Mtime: &indexedAt}, ExtractionFailed: true},
|
||||
}
|
||||
|
||||
gatewayClient.On("GetUserByClaim", mock.Anything, mock.Anything).Return(&userv1beta1.GetUserByClaimResponse{
|
||||
@@ -202,7 +204,7 @@ var _ = Describe("Searchprovider", func() {
|
||||
|
||||
err := s.IndexSpace(&sprovider.StorageSpaceId{OpaqueId: "storageid$spaceid!spaceid"}, false)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
Expect(upserted).To(ConsistOf("storageid$spaceid!outdated", "storageid$spaceid!missing", "storageid$spaceid!trashed"))
|
||||
Expect(upserted).To(ConsistOf("storageid$spaceid!outdated", "storageid$spaceid!missing", "storageid$spaceid!trashed", "storageid$spaceid!failed"))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -244,6 +246,23 @@ var _ = Describe("Searchprovider", func() {
|
||||
Entry("/", "/", false),
|
||||
)
|
||||
|
||||
It("indexes a resource whose extraction failed by name and marks it", func() {
|
||||
gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(&sprovider.StatResponse{
|
||||
Status: status.NewOK(context.Background()),
|
||||
Info: ri,
|
||||
}, nil)
|
||||
extractor.On("Extract", mock.Anything, mock.Anything, mock.Anything).Return(content.Document{Name: "scan.png"}, errors.New("tika failed to parse"))
|
||||
|
||||
var indexed search.Resource
|
||||
indexClient.On("Upsert", mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
|
||||
indexed = args.Get(1).(search.Resource)
|
||||
}).Return(nil)
|
||||
|
||||
s.UpsertItem(&sprovider.Reference{ResourceId: ri.GetId()})
|
||||
Expect(indexed.Name).To(Equal("scan.png"))
|
||||
Expect(indexed.ExtractionFailed).To(BeTrue())
|
||||
})
|
||||
|
||||
Context("with facets stored on the resource", func() {
|
||||
var (
|
||||
info *sprovider.ResourceInfo
|
||||
@@ -342,6 +361,13 @@ var _ = Describe("Searchprovider", func() {
|
||||
s.UpsertItem(&sprovider.Reference{ResourceId: info.GetId()})
|
||||
Expect(calls).To(BeEmpty())
|
||||
})
|
||||
|
||||
It("keeps the stored facets when the extraction failed", func() {
|
||||
extractor.On("Extract", mock.Anything, mock.Anything, mock.Anything).Return(content.Document{}, errors.New("tika failed to parse"))
|
||||
|
||||
s.UpsertItem(&sprovider.Reference{ResourceId: info.GetId()})
|
||||
Expect(calls).To(BeEmpty())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user