From 8cfecd8a97d085653ec3566b3485acd08b0764a8 Mon Sep 17 00:00:00 2001 From: Florian Schade Date: Thu, 31 Aug 2023 16:49:39 +0200 Subject: [PATCH 1/4] fix: search share expost --- services/search/pkg/search/service.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/services/search/pkg/search/service.go b/services/search/pkg/search/service.go index 43707a07fe..852c2b18c5 100644 --- a/services/search/pkg/search/service.go +++ b/services/search/pkg/search/service.go @@ -19,14 +19,15 @@ import ( "github.com/cs3org/reva/v2/pkg/storage/utils/walker" "github.com/cs3org/reva/v2/pkg/storagespace" "github.com/cs3org/reva/v2/pkg/utils" + "golang.org/x/sync/errgroup" + "google.golang.org/protobuf/types/known/fieldmaskpb" + "github.com/owncloud/ocis/v2/ocis-pkg/log" searchmsg "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/search/v0" searchsvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/search/v0" "github.com/owncloud/ocis/v2/services/search/pkg/config" "github.com/owncloud/ocis/v2/services/search/pkg/content" "github.com/owncloud/ocis/v2/services/search/pkg/engine" - "golang.org/x/sync/errgroup" - "google.golang.org/protobuf/types/known/fieldmaskpb" ) //go:generate mockery --name=Searcher @@ -332,9 +333,6 @@ func (s *Service) searchIndex(ctx context.Context, req *searchsvc.SearchRequest, } rootName = space.GetRootInfo().GetPath() permissions = space.GetRootInfo().GetPermissionSet() - if req.Ref == nil && utils.MakeRelativePath(searchPathPrefix) == utils.MakeRelativePath(rootName) { - searchPathPrefix = "." - } s.logger.Debug().Interface("grantSpace", space).Interface("mountpointRootId", mountpointRootID).Msg("searching a grant") case _spaceTypePersonal, _spaceTypeProject: permissions = space.GetRootInfo().GetPermissionSet() From 8255d9ac1b81ea029a7d392395eae2498deb534d Mon Sep 17 00:00:00 2001 From: Florian Schade Date: Fri, 1 Sep 2023 09:01:01 +0200 Subject: [PATCH 2/4] fix: search mount point inclusion --- services/search/pkg/engine/bleve.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/services/search/pkg/engine/bleve.go b/services/search/pkg/engine/bleve.go index 0d757b2609..1de9a7a6a8 100644 --- a/services/search/pkg/engine/bleve.go +++ b/services/search/pkg/engine/bleve.go @@ -24,6 +24,7 @@ import ( "github.com/cs3org/reva/v2/pkg/storagespace" "github.com/cs3org/reva/v2/pkg/utils" + searchMessage "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/search/v0" searchService "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/search/v0" "github.com/owncloud/ocis/v2/services/search/pkg/content" @@ -164,10 +165,17 @@ func (b *Bleve) Search(_ context.Context, sir *searchService.SearchIndexRequest) matches := make([]*searchMessage.Match, 0, len(res.Hits)) totalMatches := res.Total for _, hit := range res.Hits { + if sir.Ref != nil && !strings.HasPrefix(getFieldValue[string](hit.Fields, "Path"), utils.MakeRelativePath(path.Join(sir.Ref.Path, "/"))) { + totalMatches-- + continue + } + if sir.Ref != nil { - path := strings.TrimSuffix(getFieldValue[string](hit.Fields, "Path"), "/") - relRefPath := utils.MakeRelativePath(sir.Ref.Path) - if relRefPath != "." && !strings.HasPrefix(path, relRefPath+"/") { + hitPath := strings.TrimSuffix(getFieldValue[string](hit.Fields, "Path"), "/") + sirPath := utils.MakeRelativePath(sir.Ref.Path) + isMountPoint := hitPath == sirPath + + if !isMountPoint && sirPath != "." && !strings.HasPrefix(hitPath, sirPath+"/") { totalMatches-- continue } From b984c1ad01b14e774b70a51ea17fb4eb3c5bc1c8 Mon Sep 17 00:00:00 2001 From: Florian Schade Date: Fri, 1 Sep 2023 09:15:10 +0200 Subject: [PATCH 3/4] fix: acceptance tests to include path resource --- services/search/pkg/engine/bleve.go | 6 +++--- services/search/pkg/engine/bleve_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/search/pkg/engine/bleve.go b/services/search/pkg/engine/bleve.go index 1de9a7a6a8..6ffed52cdf 100644 --- a/services/search/pkg/engine/bleve.go +++ b/services/search/pkg/engine/bleve.go @@ -172,10 +172,10 @@ func (b *Bleve) Search(_ context.Context, sir *searchService.SearchIndexRequest) if sir.Ref != nil { hitPath := strings.TrimSuffix(getFieldValue[string](hit.Fields, "Path"), "/") - sirPath := utils.MakeRelativePath(sir.Ref.Path) - isMountPoint := hitPath == sirPath + requestedPath := utils.MakeRelativePath(sir.Ref.Path) + isPathRoot := hitPath == requestedPath - if !isMountPoint && sirPath != "." && !strings.HasPrefix(hitPath, sirPath+"/") { + if !isPathRoot && requestedPath != "." && !strings.HasPrefix(hitPath, requestedPath+"/") { totalMatches-- continue } diff --git a/services/search/pkg/engine/bleve_test.go b/services/search/pkg/engine/bleve_test.go index 6c54d5468e..f5692c6f40 100644 --- a/services/search/pkg/engine/bleve_test.go +++ b/services/search/pkg/engine/bleve_test.go @@ -340,7 +340,7 @@ var _ = Describe("Bleve", func() { It("search *doc* in a subfolder", func() { res, err := doSearch(rootResource.ID, "Name:*doc*", "./doc") Expect(err).ToNot(HaveOccurred()) - Expect(res.TotalMatches).To(Equal(int32(1))) + Expect(res.TotalMatches).To(Equal(int32(2))) }) It("search *file* in a root", func() { res, err := doSearch(rootResource.ID, "Name:*file*", "") From a885c8ad5c04bda132aa25047eeafe2fbc569c69 Mon Sep 17 00:00:00 2001 From: Florian Schade Date: Fri, 1 Sep 2023 10:36:07 +0200 Subject: [PATCH 4/4] fix: failing tests and filter out specific matches --- services/search/pkg/engine/bleve.go | 9 ++------- services/search/pkg/search/service.go | 11 +++++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/services/search/pkg/engine/bleve.go b/services/search/pkg/engine/bleve.go index 6ffed52cdf..06973515c5 100644 --- a/services/search/pkg/engine/bleve.go +++ b/services/search/pkg/engine/bleve.go @@ -165,17 +165,12 @@ func (b *Bleve) Search(_ context.Context, sir *searchService.SearchIndexRequest) matches := make([]*searchMessage.Match, 0, len(res.Hits)) totalMatches := res.Total for _, hit := range res.Hits { - if sir.Ref != nil && !strings.HasPrefix(getFieldValue[string](hit.Fields, "Path"), utils.MakeRelativePath(path.Join(sir.Ref.Path, "/"))) { - totalMatches-- - continue - } - if sir.Ref != nil { hitPath := strings.TrimSuffix(getFieldValue[string](hit.Fields, "Path"), "/") requestedPath := utils.MakeRelativePath(sir.Ref.Path) - isPathRoot := hitPath == requestedPath + isRoot := hitPath == requestedPath - if !isPathRoot && requestedPath != "." && !strings.HasPrefix(hitPath, requestedPath+"/") { + if !isRoot && requestedPath != "." && !strings.HasPrefix(hitPath, requestedPath+"/") { totalMatches-- continue } diff --git a/services/search/pkg/search/service.go b/services/search/pkg/search/service.go index 852c2b18c5..9edfe10d22 100644 --- a/services/search/pkg/search/service.go +++ b/services/search/pkg/search/service.go @@ -359,6 +359,8 @@ func (s *Service) searchIndex(ctx context.Context, req *searchsvc.SearchRequest, s.logger.Debug().Interface("searchRequest", searchRequest).Str("duration", fmt.Sprint(duration)).Str("space", space.Id.OpaqueId).Int("hits", len(res.Matches)).Msg("space search done") } + var matches []*searchmsg.Match + for _, match := range res.Matches { if mountpointPrefix != "" { match.Entity.Ref.Path = utils.MakeRelativePath(strings.TrimPrefix(match.Entity.Ref.Path, mountpointPrefix)) @@ -372,7 +374,16 @@ func (s *Service) searchIndex(ctx context.Context, req *searchsvc.SearchRequest, isMountpoint := isShared && match.GetEntity().GetRef().GetPath() == "." isDir := match.GetEntity().GetMimeType() == "httpd/unix-directory" match.Entity.Permissions = convertToWebDAVPermissions(isShared, isMountpoint, isDir, permissions) + + if req.Ref != nil && searchPathPrefix == "/"+match.Entity.Name { + continue + } + + matches = append(matches, match) } + + res.Matches = matches + return res, nil }