Skip to content

Commit

Permalink
feat: search solr documents to use borer codecs
Browse files Browse the repository at this point in the history
  • Loading branch information
jachro committed Jan 25, 2024
1 parent 6661d53 commit ac2e5e2
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
11 changes: 0 additions & 11 deletions modules/search-solr-client/src/main/avro/documents.avdl

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ac2e5e2

Please sign in to comment.