mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-04 10:29:34 +00:00
Enhance search mode to search in all items
This commit is contained in:
parent
bb8a6c054b
commit
d5022f883e
@ -220,6 +220,7 @@ object OSimpleSearch {
|
||||
settings.searchMode match {
|
||||
case SearchMode.Trashed => q.withFix(_.andQuery(ItemQuery.Expr.Trashed))
|
||||
case SearchMode.Normal => q.withFix(_.andQuery(ItemQuery.Expr.ValidItemStates))
|
||||
case SearchMode.All => q.withFix(_.andQuery(ItemQuery.Expr.ValidItemsOrTrashed))
|
||||
}
|
||||
fulltextQuery match {
|
||||
case Some(ftq) if settings.useFTS =>
|
||||
@ -282,6 +283,7 @@ object OSimpleSearch {
|
||||
settings.searchMode match {
|
||||
case SearchMode.Trashed => q.withFix(_.andQuery(ItemQuery.Expr.Trashed))
|
||||
case SearchMode.Normal => q.withFix(_.andQuery(ItemQuery.Expr.ValidItemStates))
|
||||
case SearchMode.All => q.withFix(_.andQuery(ItemQuery.Expr.ValidItemsOrTrashed))
|
||||
}
|
||||
fulltextQuery match {
|
||||
case Some(ftq) if settings.useFTS =>
|
||||
|
@ -52,6 +52,9 @@ object ItemState {
|
||||
val invalidStates: NonEmptyList[ItemState] =
|
||||
NonEmptyList.of(Premature, Processing)
|
||||
|
||||
val validStatesAndDeleted: NonEmptyList[ItemState] =
|
||||
validStates.append(deleted)
|
||||
|
||||
def unsafe(str: String): ItemState =
|
||||
fromString(str).fold(sys.error, identity)
|
||||
|
||||
|
@ -22,11 +22,13 @@ object SearchMode {
|
||||
|
||||
final case object Normal extends SearchMode
|
||||
final case object Trashed extends SearchMode
|
||||
final case object All extends SearchMode
|
||||
|
||||
def fromString(str: String): Either[String, SearchMode] =
|
||||
str.toLowerCase match {
|
||||
case "normal" => Right(Normal)
|
||||
case "trashed" => Right(Trashed)
|
||||
case "all" => Right(All)
|
||||
case _ => Left(s"Invalid search mode: $str")
|
||||
}
|
||||
|
||||
|
@ -123,8 +123,9 @@ object ItemQuery {
|
||||
final case class ChecksumMatch(checksum: String) extends Expr
|
||||
final case class AttachId(id: String) extends Expr
|
||||
|
||||
final case object ValidItemStates extends Expr
|
||||
final case object Trashed extends Expr
|
||||
final case object ValidItemStates extends Expr
|
||||
final case object Trashed extends Expr
|
||||
final case object ValidItemsOrTrashed extends Expr
|
||||
|
||||
// things that can be expressed with terms above
|
||||
sealed trait MacroExpr extends Expr {
|
||||
|
@ -79,6 +79,8 @@ object ExprUtil {
|
||||
expr
|
||||
case Trashed =>
|
||||
expr
|
||||
case ValidItemsOrTrashed =>
|
||||
expr
|
||||
}
|
||||
|
||||
private def spliceAnd(nodes: Nel[Expr]): Nel[Expr] =
|
||||
|
@ -4228,6 +4228,7 @@ components:
|
||||
enum:
|
||||
- normal
|
||||
- trashed
|
||||
- all
|
||||
default: normal
|
||||
description: |
|
||||
Specify whether the search query should apply to
|
||||
@ -5978,10 +5979,12 @@ components:
|
||||
searchMode:
|
||||
name: searchMode
|
||||
in: query
|
||||
description: Whether to search in soft-deleted items only.
|
||||
schema:
|
||||
type: string
|
||||
format: searchmode
|
||||
description: |
|
||||
Specify whether the search query should apply to soft-deleted
|
||||
items or not.
|
||||
name:
|
||||
name: name
|
||||
in: path
|
||||
|
@ -129,6 +129,9 @@ object ItemQueryGenerator {
|
||||
case Expr.Trashed =>
|
||||
tables.item.state === ItemState.Deleted
|
||||
|
||||
case Expr.ValidItemsOrTrashed =>
|
||||
tables.item.state.in(ItemState.validStatesAndDeleted)
|
||||
|
||||
case Expr.TagIdsMatch(op, tags) =>
|
||||
val ids = tags.toList.flatMap(s => Ident.fromString(s).toOption)
|
||||
Nel
|
||||
|
Loading…
x
Reference in New Issue
Block a user