diff --git a/modules/search-api/src/test/scala/io/renku/search/api/SearchApiSpec.scala b/modules/search-api/src/test/scala/io/renku/search/api/SearchApiSpec.scala index ba7a97ff..b704e3b9 100644 --- a/modules/search-api/src/test/scala/io/renku/search/api/SearchApiSpec.scala +++ b/modules/search-api/src/test/scala/io/renku/search/api/SearchApiSpec.scala @@ -66,12 +66,17 @@ class SearchApiSpec extends CatsEffectSuite with SearchSolrSuite: for { client <- IO(searchSolrClient()) searchApi = new SearchApiImpl[IO](client) - _ <- client.upsert((project1 :: project2 :: Nil).map(_.widen)) + _ <- client.upsert((project1 :: project2 :: user :: Nil).map(_.widen)) results <- searchApi - .query(AuthContext.anonymous)(mkQuery("matching")) + .query(AuthContext.anonymous)(mkQuery("matching type:Project")) .map(_.fold(err => fail(s"Calling Search API failed with $err"), identity)) - expected = toApiEntities(project1).toSet + expected = toApiEntities( + project1.copy( + creatorDetails = ResponseBody.single(user).some, + namespaceDetails = ResponseBody.single(user).some + ) + ).toSet obtained = results.items.map(scoreToNone).toSet } yield assert( expected.diff(obtained).isEmpty, @@ -122,6 +127,6 @@ class SearchApiSpec extends CatsEffectSuite with SearchSolrSuite: case e: SearchEntity.Group => e.copy(score = None) private def mkQuery(phrase: String): QueryInput = - QueryInput.pageOne(Query.parse(s"Fields $phrase").fold(sys.error, identity)) + QueryInput.pageOne(Query.parse(phrase).fold(sys.error, identity)) private def toApiEntities(e: EntityDocument*) = e.map(EntityConverter.apply) diff --git a/modules/search-solr-client/src/main/scala/io/renku/search/solr/client/RenkuEntityQuery.scala b/modules/search-solr-client/src/main/scala/io/renku/search/solr/client/RenkuEntityQuery.scala index 28f5944c..2b951054 100644 --- a/modules/search-solr-client/src/main/scala/io/renku/search/solr/client/RenkuEntityQuery.scala +++ b/modules/search-solr-client/src/main/scala/io/renku/search/solr/client/RenkuEntityQuery.scala @@ -43,7 +43,8 @@ object RenkuEntityQuery: .addFilter( SolrToken.kindIs(DocumentKind.FullEntity).value, SolrToken.namespaceExists.value, - SolrToken.createdByExists.value + SolrToken.createdByExists.value, + "{!join from=namespace to=namespace}(_type:User OR _type:Group)" ) .addFilter(constrainRole(role).map(_.value)*) .withSort(sq.sort) diff --git a/modules/search-solr-client/src/test/scala/io/renku/search/solr/client/SearchSolrClientSpec.scala b/modules/search-solr-client/src/test/scala/io/renku/search/solr/client/SearchSolrClientSpec.scala index 1e96482b..407db568 100644 --- a/modules/search-solr-client/src/test/scala/io/renku/search/solr/client/SearchSolrClientSpec.scala +++ b/modules/search-solr-client/src/test/scala/io/renku/search/solr/client/SearchSolrClientSpec.scala @@ -43,34 +43,35 @@ class SearchSolrClientSpec extends CatsEffectSuite with SearchSolrSuite: override def munitFixtures: Seq[munit.AnyFixture[?]] = List(solrServer, searchSolrClient) - // test("ignore entities with non-resolvable namespace"): - // val user = userDocumentGen.generateOne - // val group = groupDocumentGen.generateOne - // val project0 = projectDocumentGen( - // "project-test0", - // "project-test0 description", - // Gen.const(None), - // Gen.const(None) - // ).generateOne.copy(createdBy = user.id, namespace = group.namespace.some) - // val project1 = projectDocumentGen( - // "project-test1", - // "project-test1 description", - // Gen.const(None), - // Gen.const(None) - // ).generateOne.copy(createdBy = user.id, namespace = group.namespace.some) + test("ignore entities with non-resolvable namespace"): + val user = userDocumentGen.generateOne + val group = groupDocumentGen.generateOne + val randomNs = ModelGenerators.namespaceGen.generateOne + val project0 = projectDocumentGenForInsert.generateOne.copy( + createdBy = user.id, + namespace = group.namespace.some + ) + val project1 = projectDocumentGenForInsert.generateOne.copy( + createdBy = user.id, + namespace = randomNs.some + ) - // for - // client <- IO(searchSolrClient()) - // _ <- client.upsert(Seq(project0.widen, project1.widen, user.widen, group.widen)) + for + client <- IO(searchSolrClient()) + _ <- client.upsert(Seq(project0.widen, project1.widen, user.widen, group.widen)) - // qr <- client.queryEntity( - // SearchRole.admin(Id("admin")), - // Query.parse("test0").toOption.get, - // 10, - // 0 - // ) - // _ = assertEquals(qr.responseBody.docs.size, 1) - // yield () + qr <- client.queryEntity( + SearchRole.admin(Id("admin")), + Query.empty, + 10, + 0 + ) + _ = assert( + !qr.responseBody.docs.map(_.id).contains(project1.id), + "project with non-existing namespace was in the result set" + ) + _ = assertEquals(qr.responseBody.docs.size, 3) + yield () test("ignore entities with non-existing namespace"): val user = userDocumentGen.generateOne @@ -227,7 +228,7 @@ class SearchSolrClientSpec extends CatsEffectSuite with SearchSolrSuite: .generateOne .copy(createdBy = user.id, namespace = user.namespace) ) - _ <- client.upsertSuccess(Seq(project)) + _ <- client.upsertSuccess(Seq(project, user)) member = entityMembers.allIds.head nonMember <- IO(ModelGenerators.idGen.generateOne) query = Query(Query.Segment.idIs(project.id.value))