Repository: owncloud/ocis
Pull request #7191 (2023-09-01 09:46:51)

[tests-only][full-ci] Backport move search related file
This PR is backported from master https://github.com/owncloud/ocis/pull/7139

sonarcloud[bot]: Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=owncloud_ocis&pullRequest=7191)

[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=owncloud_ocis&pullRequest=7191&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=owncloud_ocis&pullRequest=7191&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=owncloud_ocis&pullRequest=7191&resolved=false&types=BUG)  
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=owncloud_ocis&pullRequest=7191&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=owncloud_ocis&pullRequest=7191&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=owncloud_ocis&pullRequest=7191&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=owncloud_ocis&pullRequest=7191&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=owncloud_ocis&pullRequest=7191&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=owncloud_ocis&pullRequest=7191&resolved=false&types=SECURITY_HOTSPOT)  
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=owncloud_ocis&pullRequest=7191&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=owncloud_ocis&pullRequest=7191&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=owncloud_ocis&pullRequest=7191&resolved=false&types=CODE_SMELL)

[![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=owncloud_ocis&pullRequest=7191&metric=coverage&view=list) No Coverage information  
[![No Duplication information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/NoDuplicationInfo-16px.png 'No Duplication information')](https://sonarcloud.io/component_measures?id=owncloud_ocis&pullRequest=7191&metric=duplicated_lines_density&view=list) No Duplication information



Patch:
diff --git a/.drone.star b/.drone.star
index 98926c9a943..e7bbf6d393a 100644
--- a/.drone.star
+++ b/.drone.star
@@ -150,9 +150,9 @@ config = {
                 "OCIS_ADD_RUN_SERVICES": "antivirus",
             },
         },
-        "apiFullTextSearch": {
+        "apiSearch": {
             "suites": [
-                "apiFullTextSearch",
+                "apiSearch",
             ],
             "skip": False,
             "tikaNeeded": True,
diff --git a/services/search/pkg/engine/bleve.go b/services/search/pkg/engine/bleve.go
index 06973515c57..0d757b2609a 100644
--- a/services/search/pkg/engine/bleve.go
+++ b/services/search/pkg/engine/bleve.go
@@ -24,7 +24,6 @@ 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"
@@ -166,11 +165,9 @@ func (b *Bleve) Search(_ context.Context, sir *searchService.SearchIndexRequest)
 	totalMatches := res.Total
 	for _, hit := range res.Hits {
 		if sir.Ref != nil {
-			hitPath := strings.TrimSuffix(getFieldValue[string](hit.Fields, "Path"), "/")
-			requestedPath := utils.MakeRelativePath(sir.Ref.Path)
-			isRoot := hitPath == requestedPath
-
-			if !isRoot && requestedPath != "." && !strings.HasPrefix(hitPath, requestedPath+"/") {
+			path := strings.TrimSuffix(getFieldValue[string](hit.Fields, "Path"), "/")
+			relRefPath := utils.MakeRelativePath(sir.Ref.Path)
+			if relRefPath != "." && !strings.HasPrefix(path, relRefPath+"/") {
 				totalMatches--
 				continue
 			}
diff --git a/services/search/pkg/search/service.go b/services/search/pkg/search/service.go
index 9edfe10d223..43707a07fe1 100644
--- a/services/search/pkg/search/service.go
+++ b/services/search/pkg/search/service.go
@@ -19,15 +19,14 @@ 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
@@ -333,6 +332,9 @@ 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()
@@ -359,8 +361,6 @@ 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))
@@ -374,16 +374,7 @@ 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
 }
 


Test patch:
diff --git a/services/search/pkg/engine/bleve_test.go b/services/search/pkg/engine/bleve_test.go
index f5692c6f40d..6c54d5468ef 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(2)))
+				Expect(res.TotalMatches).To(Equal(int32(1)))
 			})
 			It("search *file* in a root", func() {
 				res, err := doSearch(rootResource.ID, "Name:*file*", "")
diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml
index 2b11684eb3a..6bb5665f7ee 100644
--- a/tests/acceptance/config/behat.yml
+++ b/tests/acceptance/config/behat.yml
@@ -41,7 +41,6 @@ default:
         - NotificationContext:
         - OCSContext:
         - PublicWebDavContext:
-        - SearchContext:
         - TagContext:
         - TUSContext:
         - SpacesTUSContext:
@@ -62,7 +61,6 @@ default:
         - FilesVersionsContext:
         - OCSContext:
         - PublicWebDavContext:
-        - SearchContext:
         - TrashbinContext:
         - WebDavPropertiesContext:
         - TUSContext:
@@ -115,11 +113,9 @@ default:
         - FilesVersionsContext:
         - OCSContext:
         - PublicWebDavContext:
-        - SearchContext:
         - TUSContext:
         - SpacesTUSContext:
         - OcisConfigContext:
-        - TagContext:
         - TrashbinContext:
 
     apiCors:
@@ -195,9 +191,9 @@ default:
         - PublicWebDavContext:
         - ArchiverContext:
 
-    apiFullTextSearch:
+    apiSearch:
       paths:
-        - '%paths.base%/../features/apiFullTextSearch'
+        - '%paths.base%/../features/apiSearch'
       context: *common_ldap_suite_context
       contexts:
         - SettingsContext:
@@ -210,6 +206,7 @@ default:
         - FilesVersionsContext:
         - OCSContext:
         - TrashbinContext:
+        - TagContext:
 
     apiReshare:
       paths:
diff --git a/tests/acceptance/features/apiSpaces/search.feature b/tests/acceptance/features/apiSearch/apiSpaceSearch.feature
similarity index 100%
rename from tests/acceptance/features/apiSpaces/search.feature
rename to tests/acceptance/features/apiSearch/apiSpaceSearch.feature
diff --git a/tests/acceptance/features/apiFullTextSearch/search.feature b/tests/acceptance/features/apiSearch/contentSearch.feature
similarity index 99%
rename from tests/acceptance/features/apiFullTextSearch/search.feature
rename to tests/acceptance/features/apiSearch/contentSearch.feature
index e1eb6a02e0b..7be1880d201 100644
--- a/tests/acceptance/features/apiFullTextSearch/search.feature
+++ b/tests/acceptance/features/apiSearch/contentSearch.feature
@@ -1,6 +1,6 @@
-Feature: full text search
+Feature: content search
   As a user
-  I want to do full text search
+  I want to do search resources by content
   So that I can find the files with the content I am looking for
 
   Background:
diff --git a/tests/acceptance/features/apiGraph/fullSearch.feature b/tests/acceptance/features/apiSearch/tagSearch.feature
similarity index 99%
rename from tests/acceptance/features/apiGraph/fullSearch.feature
rename to tests/acceptance/features/apiSearch/tagSearch.feature
index 4ea9cc8b964..140d9b26467 100644
--- a/tests/acceptance/features/apiGraph/fullSearch.feature
+++ b/tests/acceptance/features/apiSearch/tagSearch.feature
@@ -1,7 +1,7 @@
-Feature: full text search
+Feature: tag search
   As a user
-  I want to do full text search
-  So that I can find the files with the content I am looking for
+  I want to do search resources by tag
+  So that I can find the files with the tag I am looking for
 
   Background:
     Given user "Alice" has been created with default attributes and without skeleton files