diff --git a/modules/search-provision/src/main/scala/io/renku/search/provision/SearchProvisioner.scala b/modules/search-provision/src/main/scala/io/renku/search/provision/SearchProvisioner.scala index 568819f7..845c6fca 100644 --- a/modules/search-provision/src/main/scala/io/renku/search/provision/SearchProvisioner.scala +++ b/modules/search-provision/src/main/scala/io/renku/search/provision/SearchProvisioner.scala @@ -28,7 +28,7 @@ import io.renku.messages.ProjectCreated import io.renku.queue.client.{Message, QueueClient, QueueName} import io.renku.redis.client.RedisUrl import io.renku.search.solr.client.SearchSolrClient -import io.renku.search.solr.documents.ProjectDocument +import io.renku.search.solr.documents.Project import io.renku.solr.client.SolrConfig import scribe.Scribe @@ -68,5 +68,5 @@ private class SearchProvisionerImpl[F[_]: Async]( private def pushToSolr(pc: ProjectCreated): F[Unit] = solrClient .insertProject( - ProjectDocument(id = pc.id, name = pc.name, description = pc.description) + Project(id = pc.id, name = pc.name, description = pc.description) ) diff --git a/modules/search-provision/src/test/scala/io/renku/search/provision/SearchProvisionerSpec.scala b/modules/search-provision/src/test/scala/io/renku/search/provision/SearchProvisionerSpec.scala index 45906d00..d559eb97 100644 --- a/modules/search-provision/src/test/scala/io/renku/search/provision/SearchProvisionerSpec.scala +++ b/modules/search-provision/src/test/scala/io/renku/search/provision/SearchProvisionerSpec.scala @@ -29,7 +29,7 @@ import io.renku.redis.client.RedisClientGenerators import io.renku.redis.client.RedisClientGenerators.* import io.renku.redis.client.util.RedisSpec import io.renku.search.solr.client.SearchSolrSpec -import io.renku.search.solr.documents.ProjectDocument +import io.renku.search.solr.documents.Project import munit.CatsEffectSuite import java.time.temporal.ChronoUnit @@ -46,7 +46,7 @@ class SearchProvisionerSpec extends CatsEffectSuite with RedisSpec with SearchSo .use { case (queueClient, solrClient) => val provisioner = new SearchProvisionerImpl(queue, queueClient, solrClient) for - solrDocs <- SignallingRef.of[IO, Set[ProjectDocument]](Set.empty) + solrDocs <- SignallingRef.of[IO, Set[Project]](Set.empty) provisioningFiber <- provisioner.provisionSolr.start @@ -81,12 +81,8 @@ class SearchProvisionerSpec extends CatsEffectSuite with RedisSpec with SearchSo uuid <- IO.randomUUID yield ProjectCreated(uuid.toString, name, description, owner, now) - private def toSolrDocument(created: ProjectCreated): ProjectDocument = - ProjectDocument( - id = created.id, - name = created.name, - description = created.description - ) + private def toSolrDocument(created: ProjectCreated): Project = + Project(created.id, created.name, created.description) override def munitFixtures: Seq[Fixture[_]] = List(withRedisClient, withSearchSolrClient) diff --git a/modules/search-solr-client/src/main/avro/documents.avdl b/modules/search-solr-client/src/main/avro/documents.avdl deleted file mode 100644 index 711768b9..00000000 --- a/modules/search-solr-client/src/main/avro/documents.avdl +++ /dev/null @@ -1,11 +0,0 @@ -@namespace("io.renku.search.solr.documents") -protocol Documents { - - /* An example record for a Project document in Solr */ - record ProjectDocument { - string discriminator = "project"; - string id; - string name; - string description; - } -} \ No newline at end of file diff --git a/modules/search-solr-client/src/main/scala/io/renku/search/solr/client/SearchSolrClient.scala b/modules/search-solr-client/src/main/scala/io/renku/search/solr/client/SearchSolrClient.scala index b2d3658a..2e849c64 100644 --- a/modules/search-solr-client/src/main/scala/io/renku/search/solr/client/SearchSolrClient.scala +++ b/modules/search-solr-client/src/main/scala/io/renku/search/solr/client/SearchSolrClient.scala @@ -20,14 +20,14 @@ package io.renku.search.solr.client import cats.effect.{Async, Resource} import fs2.io.net.Network -import io.renku.search.solr.documents.ProjectDocument +import io.renku.search.solr.documents.Project import io.renku.solr.client.{SolrClient, SolrConfig} trait SearchSolrClient[F[_]]: - def insertProject(project: ProjectDocument): F[Unit] + def insertProject(project: Project): F[Unit] - def findAllProjects: F[List[ProjectDocument]] + def findAllProjects: F[List[Project]] object SearchSolrClient: def apply[F[_]: Async: Network]( diff --git a/modules/search-solr-client/src/main/scala/io/renku/search/solr/client/SearchSolrClientImpl.scala b/modules/search-solr-client/src/main/scala/io/renku/search/solr/client/SearchSolrClientImpl.scala index 33e24fe3..987ef0dc 100644 --- a/modules/search-solr-client/src/main/scala/io/renku/search/solr/client/SearchSolrClientImpl.scala +++ b/modules/search-solr-client/src/main/scala/io/renku/search/solr/client/SearchSolrClientImpl.scala @@ -20,24 +20,19 @@ package io.renku.search.solr.client import cats.effect.Async import cats.syntax.all.* -import io.renku.avro.codec.AvroEncoder -import io.renku.avro.codec.all.given -import io.renku.search.solr.documents.ProjectDocument -import io.renku.search.solr.schema.{Discriminator, EntityDocumentSchema} +import io.renku.search.solr.documents.Project +import io.renku.search.solr.schema.EntityDocumentSchema import io.renku.solr.client.{QueryString, SolrClient} class SearchSolrClientImpl[F[_]: Async](solrClient: SolrClient[F]) extends SearchSolrClient[F]: - override def insertProject(project: ProjectDocument): F[Unit] = - solrClient.insert(ProjectDocument.SCHEMA$, Seq(project)).void + override def insertProject(project: Project): F[Unit] = + solrClient.insert(Seq(project)).void - override def findAllProjects: F[List[ProjectDocument]] = + override def findAllProjects: F[List[Project]] = solrClient - .query[ProjectDocument]( - ProjectDocument.SCHEMA$, - QueryString( - s"${EntityDocumentSchema.Fields.discriminator}:${Discriminator.project}" - ) + .query[Project]( + QueryString(s"${EntityDocumentSchema.Fields.entityType}:${Project.entityType}") ) .map(_.responseBody.docs.toList) diff --git a/modules/search-solr-client/src/main/scala/io/renku/search/solr/documents/Project.scala b/modules/search-solr-client/src/main/scala/io/renku/search/solr/documents/Project.scala new file mode 100644 index 00000000..26981c35 --- /dev/null +++ b/modules/search-solr-client/src/main/scala/io/renku/search/solr/documents/Project.scala @@ -0,0 +1,31 @@ +/* + * Copyright 2024 Swiss Data Science Center (SDSC) + * A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and + * Eidgenössische Technische Hochschule Zürich (ETHZ). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.renku.search.solr.documents + +import io.bullet.borer.derivation.MapBasedCodecs.deriveDecoder +import io.bullet.borer.{Decoder, Encoder} +import io.renku.solr.client.EncoderSupport.deriveWithDiscriminator + +final case class Project(id: String, name: String, description: String) + +object Project: + val entityType: String = "Project" + + given Encoder[Project] = deriveWithDiscriminator + given Decoder[Project] = deriveDecoder diff --git a/modules/search-solr-client/src/main/scala/io/renku/search/solr/schema/EntityDocumentSchema.scala b/modules/search-solr-client/src/main/scala/io/renku/search/solr/schema/EntityDocumentSchema.scala index d065e57f..0c6e1aff 100644 --- a/modules/search-solr-client/src/main/scala/io/renku/search/solr/schema/EntityDocumentSchema.scala +++ b/modules/search-solr-client/src/main/scala/io/renku/search/solr/schema/EntityDocumentSchema.scala @@ -24,15 +24,15 @@ object EntityDocumentSchema: object Fields: val id: FieldName = FieldName("id") - val discriminator: FieldName = FieldName("discriminator") + val entityType: FieldName = FieldName("_type") val name: FieldName = FieldName("name") val description: FieldName = FieldName("description") val initialEntityDocumentAdd: Seq[SchemaCommand] = Seq( - SchemaCommand.Add(FieldType.str(TypeName("discriminator"))), + SchemaCommand.Add(FieldType.str(TypeName("entityType"))), SchemaCommand.Add(FieldType.str(TypeName("name"))), SchemaCommand.Add(FieldType.text(TypeName("description"), Analyzer.classic)), - SchemaCommand.Add(Field(Fields.discriminator, TypeName("discriminator"))), + SchemaCommand.Add(Field(Fields.entityType, TypeName("entityType"))), SchemaCommand.Add(Field(Fields.name, TypeName("name"))), SchemaCommand.Add(Field(Fields.description, TypeName("description"))) ) diff --git a/modules/search-solr-client/src/test/scala/io/renku/search/solr/client/SearchSolrClientGenerators.scala b/modules/search-solr-client/src/test/scala/io/renku/search/solr/client/SearchSolrClientGenerators.scala index a061c0be..04828969 100644 --- a/modules/search-solr-client/src/test/scala/io/renku/search/solr/client/SearchSolrClientGenerators.scala +++ b/modules/search-solr-client/src/test/scala/io/renku/search/solr/client/SearchSolrClientGenerators.scala @@ -18,18 +18,14 @@ package io.renku.search.solr.client -import io.renku.search.solr.documents.ProjectDocument +import io.renku.search.solr.documents.Project import org.scalacheck.Gen object SearchSolrClientGenerators: - def projectDocumentGen(name: String, desc: String): Gen[ProjectDocument] = + def projectDocumentGen(name: String, desc: String): Gen[Project] = Gen.uuid.map(uuid => - ProjectDocument( - id = uuid.toString, - name = "solr-project", - description = "solr project description" - ) + Project(uuid.toString, "solr-project", "solr project description") ) extension [V](gen: Gen[V]) def generateOne: V = gen.sample.getOrElse(generateOne) 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 cd8959a6..88318eb8 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 @@ -30,6 +30,7 @@ class SearchSolrClientSpec extends CatsEffectSuite with SearchSolrSpec: projectDocumentGen("solr-project", "solr project description").generateOne for { _ <- client.insertProject(project) - _ <- client.findAllProjects.map(all => assert(all contains project)) + r <- client.findAllProjects + _ = assert(r contains project) } yield () } diff --git a/modules/solr-client/src/test/scala/io/renku/solr/client/migration/SolrMigratorSpec.scala b/modules/solr-client/src/test/scala/io/renku/solr/client/migration/SolrMigratorSpec.scala index bb6573b7..bf96c3fb 100644 --- a/modules/solr-client/src/test/scala/io/renku/solr/client/migration/SolrMigratorSpec.scala +++ b/modules/solr-client/src/test/scala/io/renku/solr/client/migration/SolrMigratorSpec.scala @@ -46,7 +46,7 @@ class SolrMigratorSpec extends CatsEffectSuite with SolrSpec with SolrTruncate: Seq(TypeName("testText"), TypeName("testInt")) ) - test("run sample migrations".ignore): + test("run sample migrations"): withSolrClient().use { client => val migrator = SchemaMigrator[IO](client) for {