From a885c8ad5c04bda132aa25047eeafe2fbc569c69 Mon Sep 17 00:00:00 2001 From: Florian Schade Date: Fri, 1 Sep 2023 10:36:07 +0200 Subject: [PATCH] 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 }