mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-05 10:59:33 +00:00
Refactoring solr/fts migration
When re-indexing everything, skip intermediate populating the index and do this as the very last step. Parameterize adding new fields by their language.
This commit is contained in:
parent
ff121d462c
commit
360cad3304
@ -1,5 +1,8 @@
|
|||||||
package docspell.ftsclient
|
package docspell.ftsclient
|
||||||
|
|
||||||
|
import cats.Functor
|
||||||
|
import cats.implicits._
|
||||||
|
|
||||||
import docspell.common._
|
import docspell.common._
|
||||||
|
|
||||||
final case class FtsMigration[F[_]](
|
final case class FtsMigration[F[_]](
|
||||||
@ -7,7 +10,13 @@ final case class FtsMigration[F[_]](
|
|||||||
engine: Ident,
|
engine: Ident,
|
||||||
description: String,
|
description: String,
|
||||||
task: F[FtsMigration.Result]
|
task: F[FtsMigration.Result]
|
||||||
)
|
) {
|
||||||
|
|
||||||
|
def changeResult(f: FtsMigration.Result => FtsMigration.Result)(implicit
|
||||||
|
F: Functor[F]
|
||||||
|
): FtsMigration[F] =
|
||||||
|
copy(task = task.map(f))
|
||||||
|
}
|
||||||
|
|
||||||
object FtsMigration {
|
object FtsMigration {
|
||||||
|
|
||||||
|
@ -126,19 +126,10 @@ object SolrSetup {
|
|||||||
lang match {
|
lang match {
|
||||||
case None =>
|
case None =>
|
||||||
run(DeleteField.command(DeleteField(field))).attempt *>
|
run(DeleteField.command(DeleteField(field))).attempt *>
|
||||||
run(AddField.command(AddField.text(field)))
|
run(AddField.command(AddField.textGeneral(field)))
|
||||||
case Some(Language.German) =>
|
case Some(lang) =>
|
||||||
run(DeleteField.command(DeleteField(field))).attempt *>
|
run(DeleteField.command(DeleteField(field))).attempt *>
|
||||||
run(AddField.command(AddField.textDE(field)))
|
run(AddField.command(AddField.textLang(field, lang)))
|
||||||
case Some(Language.English) =>
|
|
||||||
run(DeleteField.command(DeleteField(field))).attempt *>
|
|
||||||
run(AddField.command(AddField.textEN(field)))
|
|
||||||
case Some(Language.French) =>
|
|
||||||
run(DeleteField.command(DeleteField(field))).attempt *>
|
|
||||||
run(AddField.command(AddField.textFR(field)))
|
|
||||||
case Some(Language.Italian) =>
|
|
||||||
run(DeleteField.command(DeleteField(field))).attempt *>
|
|
||||||
run(AddField.command(AddField.textIT(field)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,20 +155,11 @@ object SolrSetup {
|
|||||||
def string(field: Field): AddField =
|
def string(field: Field): AddField =
|
||||||
AddField(field, "string", true, true, false)
|
AddField(field, "string", true, true, false)
|
||||||
|
|
||||||
def text(field: Field): AddField =
|
def textGeneral(field: Field): AddField =
|
||||||
AddField(field, "text_general", true, true, false)
|
AddField(field, "text_general", true, true, false)
|
||||||
|
|
||||||
def textDE(field: Field): AddField =
|
def textLang(field: Field, lang: Language): AddField =
|
||||||
AddField(field, "text_de", true, true, false)
|
AddField(field, s"text_${lang.iso2}", true, true, false)
|
||||||
|
|
||||||
def textEN(field: Field): AddField =
|
|
||||||
AddField(field, "text_en", true, true, false)
|
|
||||||
|
|
||||||
def textFR(field: Field): AddField =
|
|
||||||
AddField(field, "text_fr", true, true, false)
|
|
||||||
|
|
||||||
def textIT(field: Field): AddField =
|
|
||||||
AddField(field, "text_it", true, true, false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case class DeleteField(name: Field)
|
case class DeleteField(name: Field)
|
||||||
|
@ -14,16 +14,26 @@ object FtsWork {
|
|||||||
def apply[F[_]](f: FtsContext[F] => F[Unit]): FtsWork[F] =
|
def apply[F[_]](f: FtsContext[F] => F[Unit]): FtsWork[F] =
|
||||||
Kleisli(f)
|
Kleisli(f)
|
||||||
|
|
||||||
def allInitializeTasks[F[_]: Monad]: FtsWork[F] =
|
/** Runs all migration tasks unconditionally and inserts all data as last step. */
|
||||||
FtsWork[F](_ => ().pure[F]).tap[FtsContext[F]].flatMap { ctx =>
|
def reInitializeTasks[F[_]: Monad]: FtsWork[F] =
|
||||||
NonEmptyList.fromList(ctx.fts.initialize.map(fm => from[F](fm.task))) match {
|
FtsWork { ctx =>
|
||||||
|
val migrations =
|
||||||
|
ctx.fts.initialize.map(fm => fm.changeResult(_ => FtsMigration.Result.workDone))
|
||||||
|
|
||||||
|
NonEmptyList.fromList(migrations) match {
|
||||||
case Some(nel) =>
|
case Some(nel) =>
|
||||||
nel.reduce(semigroup[F])
|
nel
|
||||||
|
.map(fm => from[F](fm.task))
|
||||||
|
.append(insertAll[F](None))
|
||||||
|
.reduce(semigroup[F])
|
||||||
|
.run(ctx)
|
||||||
case None =>
|
case None =>
|
||||||
FtsWork[F](_ => ().pure[F])
|
().pure[F]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
def from[F[_]: FlatMap: Applicative](t: F[FtsMigration.Result]): FtsWork[F] =
|
def from[F[_]: FlatMap: Applicative](t: F[FtsMigration.Result]): FtsWork[F] =
|
||||||
Kleisli.liftF(t).flatMap(transformResult[F])
|
Kleisli.liftF(t).flatMap(transformResult[F])
|
||||||
|
|
||||||
|
@ -11,6 +11,11 @@ import docspell.joex.Config
|
|||||||
import docspell.store.records.RFtsMigration
|
import docspell.store.records.RFtsMigration
|
||||||
import docspell.store.{AddResult, Store}
|
import docspell.store.{AddResult, Store}
|
||||||
|
|
||||||
|
/** Migrating the index from the previous version to this version.
|
||||||
|
*
|
||||||
|
* The sql database stores the outcome of a migration task. If this
|
||||||
|
* task has already been applied, it is skipped.
|
||||||
|
*/
|
||||||
case class Migration[F[_]](
|
case class Migration[F[_]](
|
||||||
version: Int,
|
version: Int,
|
||||||
engine: Ident,
|
engine: Ident,
|
||||||
|
@ -46,6 +46,6 @@ object ReIndexTask {
|
|||||||
FtsWork.log[F](_.info("Clearing data failed. Continue re-indexing."))
|
FtsWork.log[F](_.info("Clearing data failed. Continue re-indexing."))
|
||||||
) ++
|
) ++
|
||||||
FtsWork.log[F](_.info("Running index initialize")) ++
|
FtsWork.log[F](_.info("Running index initialize")) ++
|
||||||
FtsWork.allInitializeTasks[F]
|
FtsWork.reInitializeTasks[F]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,9 @@ import cats.data.Kleisli
|
|||||||
|
|
||||||
package object fts {
|
package object fts {
|
||||||
|
|
||||||
|
/** Some work that must be done to advance the schema of the fulltext
|
||||||
|
* index.
|
||||||
|
*/
|
||||||
type FtsWork[F[_]] = Kleisli[F, FtsContext[F], Unit]
|
type FtsWork[F[_]] = Kleisli[F, FtsContext[F], Unit]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user