Add language to schema, extend fts-client

This commit is contained in:
Eike Kettner
2020-06-20 22:27:26 +02:00
parent 3576c45d1a
commit 1f4ff0d4c4
13 changed files with 145 additions and 54 deletions

View File

@ -7,19 +7,41 @@ import docspell.common._
* engine.
*
* It defines all operations required for integration into docspell.
* It uses data structures and terms of docspell. Implementation
* modules need to translate it to the engine that provides the
* features.
* It uses data structures from docspell. Implementation modules need
* to translate it to the engine that provides the features.
*/
trait FtsClient[F[_]] {
/** Optional operation to do some initialization tasks. This is called
* exactly once and then never again. It may be used to setup the
* database.
/** Initialization tasks. This is called exactly once and then never
* again (except when re-indexing everything). It may be used to
* setup the database.
*/
def initialize: F[Unit]
def searchBasic(q: FtsQuery): Stream[F, FtsResult]
def search(q: FtsQuery): F[FtsResult]
def searchAll(q: FtsQuery): Stream[F, FtsResult] =
Stream.eval(search(q)).flatMap { result =>
if (result.results.size < q.limit) Stream.emit(result)
else Stream.emit(result) ++ searchAll(q.nextPage)
}
/** Push all data to the index. Data with same `id' is replaced.
* Values that are `None' are removed from the index (or set to an
* empty string).
*/
def indexData(logger: Logger[F], data: Stream[F, TextData]): F[Unit]
def indexData(logger: Logger[F], data: TextData*): F[Unit] =
indexData(logger, Stream.emits(data))
/** Push all data to the index, but only update existing entries. No
* new entries are created and values that are given as `None' are
* skipped.
*/
def updateIndex(logger: Logger[F], data: Stream[F, TextData]): F[Unit]
def updateIndex(logger: Logger[F], data: TextData*): F[Unit] =
updateIndex(logger, Stream.emits(data))
}

View File

@ -6,5 +6,18 @@ import docspell.common._
*
* The query itself is a raw string. Each implementation may
* interpret it according to the system in use.
*
* Searches must only look for given collective and in the given list
* of item ids.
*/
final case class FtsQuery(q: String, collective: Ident, limit: Int, offset: Int, items: List[Ident])
final case class FtsQuery(
q: String,
collective: Ident,
items: List[Ident],
limit: Int,
offset: Int
) {
def nextPage: FtsQuery =
copy(offset = limit + offset)
}

View File

@ -23,6 +23,7 @@ object TextData {
item: Ident,
attachId: Ident,
collective: Ident,
lang: Language,
name: Option[String],
text: Option[String]
) extends TextData {
@ -35,10 +36,11 @@ object TextData {
item: Ident,
attachId: Ident,
collective: Ident,
lang: Language,
name: Option[String],
text: Option[String]
): TextData =
Attachment(item, attachId, collective, name, text)
Attachment(item, attachId, collective, lang, name, text)
final case class Item(
item: Ident,