From 211ac39a618da4303de2457944bbaece8a43c2bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Mon, 23 May 2022 15:24:39 +0200 Subject: [PATCH 1/2] Fix keeping the index in sync when directories contain special chars --- extensions/search/pkg/search/index/index.go | 14 +++++++++---- .../search/pkg/search/index/index_test.go | 20 +++++++++---------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/extensions/search/pkg/search/index/index.go b/extensions/search/pkg/search/index/index.go index e5b52264ef..8ce98b18b7 100644 --- a/extensions/search/pkg/search/index/index.go +++ b/extensions/search/pkg/search/index/index.go @@ -23,6 +23,7 @@ import ( "errors" "math" "path" + "regexp" "strings" "time" @@ -111,7 +112,7 @@ func (i *Index) markAsDeleted(id string, deleted bool) error { if doc.Type == uint64(sprovider.ResourceType_RESOURCE_TYPE_CONTAINER) { query := bleve.NewConjunctionQuery( bleve.NewQueryStringQuery("RootID:"+doc.RootID), - bleve.NewQueryStringQuery("Path:"+doc.Path+"/*"), + bleve.NewQueryStringQuery("Path:"+queryEscape(doc.Path+"/*")), ) bleveReq := bleve.NewSearchRequest(query) bleveReq.Size = math.MaxInt @@ -187,7 +188,7 @@ func (i *Index) Move(id *sprovider.ResourceId, fullPath string) error { if doc.Type == uint64(sprovider.ResourceType_RESOURCE_TYPE_CONTAINER) { query := bleve.NewConjunctionQuery( bleve.NewQueryStringQuery("RootID:"+doc.RootID), - bleve.NewQueryStringQuery("Path:"+oldName+"/*"), + bleve.NewQueryStringQuery("Path:"+queryEscape(oldName+"/*")), ) bleveReq := bleve.NewSearchRequest(query) bleveReq.Size = math.MaxInt @@ -217,8 +218,8 @@ func (i *Index) Search(ctx context.Context, req *searchsvc.SearchIndexRequest) ( query := bleve.NewConjunctionQuery( bleve.NewQueryStringQuery(req.Query), deletedQuery, // Skip documents that have been marked as deleted - bleve.NewQueryStringQuery("RootID:"+req.Ref.ResourceId.StorageId+"!"+req.Ref.ResourceId.OpaqueId), // Limit search to the space - bleve.NewQueryStringQuery("Path:"+utils.MakeRelativePath(path.Join(req.Ref.Path, "/"))+"*"), // Limit search to this directory in the space + bleve.NewQueryStringQuery("RootID:"+req.Ref.ResourceId.StorageId+"!"+req.Ref.ResourceId.OpaqueId), // Limit search to the space + bleve.NewQueryStringQuery("Path:"+queryEscape(utils.MakeRelativePath(path.Join(req.Ref.Path, "/"))+"*")), // Limit search to this directory in the space ) bleveReq := bleve.NewSearchRequest(query) bleveReq.Size = 200 @@ -340,3 +341,8 @@ func idToBleveId(id *sprovider.ResourceId) string { } return id.StorageId + "!" + id.OpaqueId } + +func queryEscape(s string) string { + re := regexp.MustCompile(`([` + regexp.QuoteMeta(`+=&|> Date: Mon, 23 May 2022 15:48:21 +0200 Subject: [PATCH 2/2] Add changelog --- changelog/unreleased/fix-index-integrity.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/unreleased/fix-index-integrity.md diff --git a/changelog/unreleased/fix-index-integrity.md b/changelog/unreleased/fix-index-integrity.md new file mode 100644 index 0000000000..2d83033cb3 --- /dev/null +++ b/changelog/unreleased/fix-index-integrity.md @@ -0,0 +1,5 @@ +Bugfix: Fix search index getting out of sync + +We fixed a problem where the search index got out of sync with child elements of a parent containing special characters. + +https://github.com/owncloud/ocis/pull/3851