mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-21 09:58:26 +00:00
Add backend operations for re-creating the full-text index
This commit is contained in:
@ -7,7 +7,7 @@ import docspell.common._
|
||||
import docspell.backend.ops._
|
||||
import docspell.joex.hk._
|
||||
import docspell.joex.notify._
|
||||
import docspell.joex.fts.MigrationTask
|
||||
import docspell.joex.fts.{MigrationTask, ReIndexTask}
|
||||
import docspell.joex.scanmailbox._
|
||||
import docspell.joex.process.ItemHandler
|
||||
import docspell.joex.scheduler._
|
||||
@ -111,6 +111,13 @@ object JoexAppImpl {
|
||||
MigrationTask.onCancel[F]
|
||||
)
|
||||
)
|
||||
.withTask(
|
||||
JobTask.json(
|
||||
ReIndexTask.taskName,
|
||||
ReIndexTask[F](cfg.fullTextSearch, fts),
|
||||
ReIndexTask.onCancel[F]
|
||||
)
|
||||
)
|
||||
.withTask(
|
||||
JobTask.json(
|
||||
HouseKeepingTask.taskName,
|
||||
|
@ -3,10 +3,11 @@ package docspell.joex.fts
|
||||
import cats.effect._
|
||||
import cats.data.{Kleisli, NonEmptyList}
|
||||
import cats.{FlatMap, Semigroup}
|
||||
import docspell.store.queries.{QAttachment, QItem}
|
||||
import docspell.common._
|
||||
import docspell.ftsclient._
|
||||
import docspell.joex.scheduler.Context
|
||||
import docspell.joex.Config
|
||||
import docspell.store.queries.{QAttachment, QItem}
|
||||
|
||||
object FtsWork {
|
||||
def apply[F[_]](f: FtsContext[F] => F[Unit]): FtsWork[F] =
|
||||
@ -21,23 +22,20 @@ object FtsWork {
|
||||
implicit def semigroup[F[_]: FlatMap]: Semigroup[FtsWork[F]] =
|
||||
Semigroup.instance((mt1, mt2) => mt1.flatMap(_ => mt2))
|
||||
|
||||
implicit final class FtsWorkOps[F[_]](mt: FtsWork[F]) {
|
||||
def ++(mn: FtsWork[F])(implicit ev: FlatMap[F]): FtsWork[F] =
|
||||
all(mt, mn)
|
||||
|
||||
def forContext(
|
||||
cfg: Config.FullTextSearch,
|
||||
fts: FtsClient[F]
|
||||
): Kleisli[F, Context[F, _], Unit] =
|
||||
mt.local(ctx => FtsContext(cfg, fts, ctx))
|
||||
}
|
||||
|
||||
// some tasks
|
||||
|
||||
def initialize[F[_]]: FtsWork[F] =
|
||||
FtsWork(_.fts.initialize)
|
||||
|
||||
def insertAll[F[_]: Effect]: FtsWork[F] =
|
||||
def clearIndex[F[_]](coll: Option[Ident]): FtsWork[F] =
|
||||
coll match {
|
||||
case Some(cid) =>
|
||||
FtsWork(ctx => ctx.fts.clear(ctx.logger, cid))
|
||||
case None =>
|
||||
FtsWork(ctx => ctx.fts.clearAll(ctx.logger))
|
||||
}
|
||||
|
||||
def insertAll[F[_]: Effect](coll: Option[Ident]): FtsWork[F] =
|
||||
FtsWork
|
||||
.all(
|
||||
FtsWork(ctx =>
|
||||
@ -45,7 +43,8 @@ object FtsWork {
|
||||
ctx.logger,
|
||||
ctx.store
|
||||
.transact(
|
||||
QAttachment.allAttachmentMetaAndName(ctx.cfg.migration.indexAllChunk)
|
||||
QAttachment
|
||||
.allAttachmentMetaAndName(coll, ctx.cfg.migration.indexAllChunk)
|
||||
)
|
||||
.map(caa =>
|
||||
TextData
|
||||
@ -64,9 +63,22 @@ object FtsWork {
|
||||
ctx.fts.indexData(
|
||||
ctx.logger,
|
||||
ctx.store
|
||||
.transact(QItem.allNameAndNotes(ctx.cfg.migration.indexAllChunk * 5))
|
||||
.transact(QItem.allNameAndNotes(coll, ctx.cfg.migration.indexAllChunk * 5))
|
||||
.map(nn => TextData.item(nn.id, nn.collective, Option(nn.name), nn.notes))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
object syntax {
|
||||
implicit final class FtsWorkOps[F[_]](mt: FtsWork[F]) {
|
||||
def ++(mn: FtsWork[F])(implicit ev: FlatMap[F]): FtsWork[F] =
|
||||
all(mt, mn)
|
||||
|
||||
def forContext(
|
||||
cfg: Config.FullTextSearch,
|
||||
fts: FtsClient[F]
|
||||
): Kleisli[F, Context[F, _], Unit] =
|
||||
mt.local(ctx => FtsContext(cfg, fts, ctx))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,9 @@ import docspell.joex.Config
|
||||
import docspell.joex.scheduler.Task
|
||||
import docspell.ftsclient._
|
||||
import docspell.store.records.RJob
|
||||
import docspell.joex.hk.HouseKeepingTask
|
||||
|
||||
object MigrationTask {
|
||||
val taskName = Ident.unsafe("full-text-index")
|
||||
val tracker = Ident.unsafe("full-text-index-tracker")
|
||||
val systemGroup = HouseKeepingTask.systemGroup
|
||||
|
||||
def apply[F[_]: ConcurrentEffect](
|
||||
cfg: Config.FullTextSearch,
|
||||
@ -37,20 +34,20 @@ object MigrationTask {
|
||||
} yield RJob.newJob(
|
||||
id,
|
||||
taskName,
|
||||
systemGroup,
|
||||
DocspellSystem.taskGroup,
|
||||
(),
|
||||
"Create full-text index",
|
||||
now,
|
||||
systemGroup,
|
||||
DocspellSystem.taskGroup,
|
||||
Priority.Low,
|
||||
Some(tracker)
|
||||
Some(DocspellSystem.migrationTaskTracker)
|
||||
)
|
||||
|
||||
private val solrEngine = Ident.unsafe("solr")
|
||||
def migrationTasks[F[_]: Effect]: List[Migration[F]] =
|
||||
List(
|
||||
Migration[F](1, solrEngine, "initialize", FtsWork.initialize[F]),
|
||||
Migration[F](2, solrEngine, "Index all from database", FtsWork.insertAll[F])
|
||||
Migration[F](2, solrEngine, "Index all from database", FtsWork.insertAll[F](None))
|
||||
)
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
package docspell.joex.fts
|
||||
|
||||
import cats.effect._
|
||||
import docspell.common._
|
||||
import docspell.joex.Config
|
||||
import docspell.joex.scheduler.Task
|
||||
import docspell.ftsclient._
|
||||
import FtsWork.syntax._
|
||||
|
||||
object ReIndexTask {
|
||||
type Args = ReIndexTaskArgs
|
||||
|
||||
val taskName = ReIndexTaskArgs.taskName
|
||||
val tracker = DocspellSystem.migrationTaskTracker
|
||||
|
||||
def apply[F[_]: ConcurrentEffect](
|
||||
cfg: Config.FullTextSearch,
|
||||
fts: FtsClient[F]
|
||||
): Task[F, Args, Unit] =
|
||||
Task
|
||||
.log[F, Args](_.info(s"Running full-text re-index now"))
|
||||
.flatMap(_ =>
|
||||
Task(ctx =>
|
||||
(FtsWork.clearIndex(ctx.args.collective) ++ FtsWork.insertAll[F](
|
||||
ctx.args.collective
|
||||
)).forContext(cfg, fts).run(ctx)
|
||||
)
|
||||
)
|
||||
|
||||
def onCancel[F[_]: Sync]: Task[F, Args, Unit] =
|
||||
Task.log[F, Args](_.warn("Cancelling full-text re-index task"))
|
||||
|
||||
}
|
@ -11,7 +11,6 @@ import docspell.store.records._
|
||||
|
||||
object HouseKeepingTask {
|
||||
private val periodicId = Ident.unsafe("docspell-houskeeping")
|
||||
val systemGroup: Ident = Ident.unsafe("docspell-system")
|
||||
|
||||
val taskName: Ident = Ident.unsafe("housekeeping")
|
||||
|
||||
@ -29,10 +28,10 @@ object HouseKeepingTask {
|
||||
.createJson(
|
||||
true,
|
||||
taskName,
|
||||
systemGroup,
|
||||
DocspellSystem.taskGroup,
|
||||
(),
|
||||
"Docspell house-keeping",
|
||||
systemGroup,
|
||||
DocspellSystem.taskGroup,
|
||||
Priority.Low,
|
||||
ce
|
||||
)
|
||||
|
Reference in New Issue
Block a user