mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Renaming things
This commit is contained in:
@ -26,8 +26,10 @@ final class SolrFtsClient[F[_]: Effect](
|
||||
def updateIndex(logger: Logger[F], data: Stream[F, TextData]): F[Unit] =
|
||||
modifyIndex(logger, data)(solrUpdate.update)
|
||||
|
||||
def modifyIndex(logger: Logger[F], data: Stream[F, TextData])(f: List[TextData] => F[Unit]): F[Unit] =
|
||||
(for {
|
||||
def modifyIndex(logger: Logger[F], data: Stream[F, TextData])(
|
||||
f: List[TextData] => F[Unit]
|
||||
): F[Unit] =
|
||||
(for {
|
||||
_ <- Stream.eval(logger.debug("Updating SOLR index"))
|
||||
chunks <- data.chunks
|
||||
res <- Stream.eval(f(chunks.toList).attempt)
|
||||
@ -37,6 +39,14 @@ final class SolrFtsClient[F[_]: Effect](
|
||||
Stream.eval(logger.error(ex)("Error updating with chunk of data"))
|
||||
}
|
||||
} yield ()).compile.drain
|
||||
|
||||
def clearAll(logger: Logger[F]): F[Unit] =
|
||||
logger.info("Deleting complete full-text index!") *>
|
||||
solrUpdate.delete("*:*")
|
||||
|
||||
def clear(logger: Logger[F], collective: Ident): F[Unit] =
|
||||
logger.info(s"Deleting full-text index for collective ${collective.id}") *>
|
||||
solrUpdate.delete(s"${Field.collectiveId.name}:${collective.id}")
|
||||
}
|
||||
|
||||
object SolrFtsClient {
|
||||
|
@ -6,6 +6,7 @@ import cats.implicits._
|
||||
import org.http4s.client.Client
|
||||
import org.http4s.circe._
|
||||
import org.http4s.client.dsl.Http4sClientDsl
|
||||
import _root_.io.circe._
|
||||
import _root_.io.circe.syntax._
|
||||
import org.log4s.getLogger
|
||||
|
||||
@ -18,6 +19,7 @@ trait SolrUpdate[F[_]] {
|
||||
|
||||
def update(tds: List[TextData]): F[Unit]
|
||||
|
||||
def delete(q: String): F[Unit]
|
||||
}
|
||||
|
||||
object SolrUpdate {
|
||||
@ -44,6 +46,11 @@ object SolrUpdate {
|
||||
client.expect[String](req).map(r => logger.debug(s"Req: $req Response: $r"))
|
||||
}
|
||||
|
||||
def delete(q: String): F[Unit] = {
|
||||
val req = Method.POST(Delete(q).asJson, url)
|
||||
client.expect[String](req).map(r => logger.debug(s"Req: $req Response: $r"))
|
||||
}
|
||||
|
||||
private val minOneChange: TextData => Boolean =
|
||||
_ match {
|
||||
case td: TextData.Attachment =>
|
||||
@ -52,5 +59,16 @@ object SolrUpdate {
|
||||
td.name.isDefined || td.notes.isDefined
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
case class Delete(query: String)
|
||||
object Delete {
|
||||
implicit val jsonEncoder: Encoder[Delete] =
|
||||
new Encoder[Delete] {
|
||||
def apply(d: Delete): Json =
|
||||
Json.obj(
|
||||
("delete", Json.obj("query" -> d.query.asJson))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user