Fix sort when using fulltext only

This commit is contained in:
Eike Kettner 2021-03-08 00:46:36 +01:00
parent c6032ff279
commit 7b1ec97c97
5 changed files with 44 additions and 24 deletions

View File

@ -52,37 +52,41 @@ object OSimpleSearch {
sealed trait Items {
def fold[A](
f1: Vector[OFulltext.FtsItem] => A,
f2: Vector[OFulltext.FtsItemWithTags] => A,
f1: Items.FtsItems => A,
f2: Items.FtsItemsFull => A,
f3: Vector[OItemSearch.ListItem] => A,
f4: Vector[OItemSearch.ListItemWithTags] => A
): A
}
object Items {
def ftsItems(items: Vector[OFulltext.FtsItem]): Items =
FtsItems(items)
def ftsItems(indexOnly: Boolean)(items: Vector[OFulltext.FtsItem]): Items =
FtsItems(items, indexOnly)
case class FtsItems(items: Vector[OFulltext.FtsItem]) extends Items {
case class FtsItems(items: Vector[OFulltext.FtsItem], indexOnly: Boolean)
extends Items {
def fold[A](
f1: Vector[OFulltext.FtsItem] => A,
f2: Vector[OFulltext.FtsItemWithTags] => A,
f1: FtsItems => A,
f2: FtsItemsFull => A,
f3: Vector[OItemSearch.ListItem] => A,
f4: Vector[OItemSearch.ListItemWithTags] => A
): A = f1(items)
): A = f1(this)
}
def ftsItemsFull(items: Vector[OFulltext.FtsItemWithTags]): Items =
FtsItemsFull(items)
def ftsItemsFull(indexOnly: Boolean)(
items: Vector[OFulltext.FtsItemWithTags]
): Items =
FtsItemsFull(items, indexOnly)
case class FtsItemsFull(items: Vector[OFulltext.FtsItemWithTags]) extends Items {
case class FtsItemsFull(items: Vector[OFulltext.FtsItemWithTags], indexOnly: Boolean)
extends Items {
def fold[A](
f1: Vector[OFulltext.FtsItem] => A,
f2: Vector[OFulltext.FtsItemWithTags] => A,
f1: FtsItems => A,
f2: FtsItemsFull => A,
f3: Vector[OItemSearch.ListItem] => A,
f4: Vector[OItemSearch.ListItemWithTags] => A
): A = f2(items)
): A = f2(this)
}
def itemsPlain(items: Vector[OItemSearch.ListItem]): Items =
@ -90,8 +94,8 @@ object OSimpleSearch {
case class ItemsPlain(items: Vector[OItemSearch.ListItem]) extends Items {
def fold[A](
f1: Vector[OFulltext.FtsItem] => A,
f2: Vector[OFulltext.FtsItemWithTags] => A,
f1: FtsItems => A,
f2: FtsItemsFull => A,
f3: Vector[OItemSearch.ListItem] => A,
f4: Vector[OItemSearch.ListItemWithTags] => A
): A = f3(items)
@ -102,8 +106,8 @@ object OSimpleSearch {
case class ItemsFull(items: Vector[OItemSearch.ListItemWithTags]) extends Items {
def fold[A](
f1: Vector[OFulltext.FtsItem] => A,
f2: Vector[OFulltext.FtsItemWithTags] => A,
f1: FtsItems => A,
f2: FtsItemsFull => A,
f3: Vector[OItemSearch.ListItem] => A,
f4: Vector[OItemSearch.ListItemWithTags] => A
): A = f4(items)
@ -190,7 +194,7 @@ object OSimpleSearch {
q.fix.account,
settings.batch
)
.map(Items.ftsItemsFull)
.map(Items.ftsItemsFull(true))
else if (settings.resolveDetails)
fts
.findItemsWithTags(settings.maxNoteLen)(
@ -198,11 +202,11 @@ object OSimpleSearch {
OFulltext.FtsInput(ftq),
settings.batch
)
.map(Items.ftsItemsFull)
.map(Items.ftsItemsFull(false))
else
fts
.findItems(settings.maxNoteLen)(q, OFulltext.FtsInput(ftq), settings.batch)
.map(Items.ftsItems)
.map(Items.ftsItems(false))
case _ =>
if (settings.resolveDetails)

View File

@ -29,6 +29,11 @@ class FulltextExtractTest extends FunSuite {
findFts("content:\"what OR hello\""),
Result.Success(ItemQuery.all.expr, "what OR hello".some)
)
assertEquals(
findFts("(& content:\"what OR hello\" )"),
Result.Success(ItemQuery.all.expr, "what OR hello".some)
)
}
test("find no fulltext") {

View File

@ -9,7 +9,6 @@
<logger name="docspell" level="debug" />
<logger name="emil" level="debug"/>
<logger name="docspell.store.queries.QItem" level="trace"/>
<root level="INFO">
<appender-ref ref="STDOUT" />

View File

@ -224,6 +224,10 @@ trait Conversions {
if (v.isEmpty) ItemLightList(Nil)
else ItemLightList(List(ItemLightGroup("Results", v.map(mkItemLightWithTags).toList)))
def mkItemListFtsPlain(v: Vector[OFulltext.FtsItem]): ItemLightList =
if (v.isEmpty) ItemLightList(Nil)
else ItemLightList(List(ItemLightGroup("Results", v.map(mkItemLight).toList)))
def mkItemLight(i: OItemSearch.ListItem): ItemLight =
ItemLight(
i.id,

View File

@ -497,14 +497,22 @@ object ItemRoutes {
)(settings: OSimpleSearch.Settings, fixQuery: Query.Fix, itemQuery: ItemQueryString) = {
import dsl._
def convertFts(res: OSimpleSearch.Items.FtsItems): ItemLightList =
if (res.indexOnly) Conversions.mkItemListFtsPlain(res.items)
else Conversions.mkItemListFts(res.items)
def convertFtsFull(res: OSimpleSearch.Items.FtsItemsFull): ItemLightList =
if (res.indexOnly) Conversions.mkItemListWithTagsFtsPlain(res.items)
else Conversions.mkItemListWithTagsFts(res.items)
backend.simpleSearch
.searchByString(settings)(fixQuery, itemQuery)
.flatMap {
case StringSearchResult.Success(items) =>
Ok(
items.fold(
Conversions.mkItemListFts,
Conversions.mkItemListWithTagsFts,
convertFts,
convertFtsFull,
Conversions.mkItemList,
Conversions.mkItemListWithTags
)