mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-05 22:55:58 +00:00
Fix sort when using fulltext only
This commit is contained in:
parent
c6032ff279
commit
7b1ec97c97
@ -52,37 +52,41 @@ object OSimpleSearch {
|
|||||||
|
|
||||||
sealed trait Items {
|
sealed trait Items {
|
||||||
def fold[A](
|
def fold[A](
|
||||||
f1: Vector[OFulltext.FtsItem] => A,
|
f1: Items.FtsItems => A,
|
||||||
f2: Vector[OFulltext.FtsItemWithTags] => A,
|
f2: Items.FtsItemsFull => A,
|
||||||
f3: Vector[OItemSearch.ListItem] => A,
|
f3: Vector[OItemSearch.ListItem] => A,
|
||||||
f4: Vector[OItemSearch.ListItemWithTags] => A
|
f4: Vector[OItemSearch.ListItemWithTags] => A
|
||||||
): A
|
): A
|
||||||
|
|
||||||
}
|
}
|
||||||
object Items {
|
object Items {
|
||||||
def ftsItems(items: Vector[OFulltext.FtsItem]): Items =
|
def ftsItems(indexOnly: Boolean)(items: Vector[OFulltext.FtsItem]): Items =
|
||||||
FtsItems(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](
|
def fold[A](
|
||||||
f1: Vector[OFulltext.FtsItem] => A,
|
f1: FtsItems => A,
|
||||||
f2: Vector[OFulltext.FtsItemWithTags] => A,
|
f2: FtsItemsFull => A,
|
||||||
f3: Vector[OItemSearch.ListItem] => A,
|
f3: Vector[OItemSearch.ListItem] => A,
|
||||||
f4: Vector[OItemSearch.ListItemWithTags] => A
|
f4: Vector[OItemSearch.ListItemWithTags] => A
|
||||||
): A = f1(items)
|
): A = f1(this)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def ftsItemsFull(items: Vector[OFulltext.FtsItemWithTags]): Items =
|
def ftsItemsFull(indexOnly: Boolean)(
|
||||||
FtsItemsFull(items)
|
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](
|
def fold[A](
|
||||||
f1: Vector[OFulltext.FtsItem] => A,
|
f1: FtsItems => A,
|
||||||
f2: Vector[OFulltext.FtsItemWithTags] => A,
|
f2: FtsItemsFull => A,
|
||||||
f3: Vector[OItemSearch.ListItem] => A,
|
f3: Vector[OItemSearch.ListItem] => A,
|
||||||
f4: Vector[OItemSearch.ListItemWithTags] => A
|
f4: Vector[OItemSearch.ListItemWithTags] => A
|
||||||
): A = f2(items)
|
): A = f2(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
def itemsPlain(items: Vector[OItemSearch.ListItem]): Items =
|
def itemsPlain(items: Vector[OItemSearch.ListItem]): Items =
|
||||||
@ -90,8 +94,8 @@ object OSimpleSearch {
|
|||||||
|
|
||||||
case class ItemsPlain(items: Vector[OItemSearch.ListItem]) extends Items {
|
case class ItemsPlain(items: Vector[OItemSearch.ListItem]) extends Items {
|
||||||
def fold[A](
|
def fold[A](
|
||||||
f1: Vector[OFulltext.FtsItem] => A,
|
f1: FtsItems => A,
|
||||||
f2: Vector[OFulltext.FtsItemWithTags] => A,
|
f2: FtsItemsFull => A,
|
||||||
f3: Vector[OItemSearch.ListItem] => A,
|
f3: Vector[OItemSearch.ListItem] => A,
|
||||||
f4: Vector[OItemSearch.ListItemWithTags] => A
|
f4: Vector[OItemSearch.ListItemWithTags] => A
|
||||||
): A = f3(items)
|
): A = f3(items)
|
||||||
@ -102,8 +106,8 @@ object OSimpleSearch {
|
|||||||
|
|
||||||
case class ItemsFull(items: Vector[OItemSearch.ListItemWithTags]) extends Items {
|
case class ItemsFull(items: Vector[OItemSearch.ListItemWithTags]) extends Items {
|
||||||
def fold[A](
|
def fold[A](
|
||||||
f1: Vector[OFulltext.FtsItem] => A,
|
f1: FtsItems => A,
|
||||||
f2: Vector[OFulltext.FtsItemWithTags] => A,
|
f2: FtsItemsFull => A,
|
||||||
f3: Vector[OItemSearch.ListItem] => A,
|
f3: Vector[OItemSearch.ListItem] => A,
|
||||||
f4: Vector[OItemSearch.ListItemWithTags] => A
|
f4: Vector[OItemSearch.ListItemWithTags] => A
|
||||||
): A = f4(items)
|
): A = f4(items)
|
||||||
@ -190,7 +194,7 @@ object OSimpleSearch {
|
|||||||
q.fix.account,
|
q.fix.account,
|
||||||
settings.batch
|
settings.batch
|
||||||
)
|
)
|
||||||
.map(Items.ftsItemsFull)
|
.map(Items.ftsItemsFull(true))
|
||||||
else if (settings.resolveDetails)
|
else if (settings.resolveDetails)
|
||||||
fts
|
fts
|
||||||
.findItemsWithTags(settings.maxNoteLen)(
|
.findItemsWithTags(settings.maxNoteLen)(
|
||||||
@ -198,11 +202,11 @@ object OSimpleSearch {
|
|||||||
OFulltext.FtsInput(ftq),
|
OFulltext.FtsInput(ftq),
|
||||||
settings.batch
|
settings.batch
|
||||||
)
|
)
|
||||||
.map(Items.ftsItemsFull)
|
.map(Items.ftsItemsFull(false))
|
||||||
else
|
else
|
||||||
fts
|
fts
|
||||||
.findItems(settings.maxNoteLen)(q, OFulltext.FtsInput(ftq), settings.batch)
|
.findItems(settings.maxNoteLen)(q, OFulltext.FtsInput(ftq), settings.batch)
|
||||||
.map(Items.ftsItems)
|
.map(Items.ftsItems(false))
|
||||||
|
|
||||||
case _ =>
|
case _ =>
|
||||||
if (settings.resolveDetails)
|
if (settings.resolveDetails)
|
||||||
|
@ -29,6 +29,11 @@ class FulltextExtractTest extends FunSuite {
|
|||||||
findFts("content:\"what OR hello\""),
|
findFts("content:\"what OR hello\""),
|
||||||
Result.Success(ItemQuery.all.expr, "what OR hello".some)
|
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") {
|
test("find no fulltext") {
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
<logger name="docspell" level="debug" />
|
<logger name="docspell" level="debug" />
|
||||||
<logger name="emil" level="debug"/>
|
<logger name="emil" level="debug"/>
|
||||||
<logger name="docspell.store.queries.QItem" level="trace"/>
|
|
||||||
|
|
||||||
<root level="INFO">
|
<root level="INFO">
|
||||||
<appender-ref ref="STDOUT" />
|
<appender-ref ref="STDOUT" />
|
||||||
|
@ -224,6 +224,10 @@ trait Conversions {
|
|||||||
if (v.isEmpty) ItemLightList(Nil)
|
if (v.isEmpty) ItemLightList(Nil)
|
||||||
else ItemLightList(List(ItemLightGroup("Results", v.map(mkItemLightWithTags).toList)))
|
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 =
|
def mkItemLight(i: OItemSearch.ListItem): ItemLight =
|
||||||
ItemLight(
|
ItemLight(
|
||||||
i.id,
|
i.id,
|
||||||
|
@ -497,14 +497,22 @@ object ItemRoutes {
|
|||||||
)(settings: OSimpleSearch.Settings, fixQuery: Query.Fix, itemQuery: ItemQueryString) = {
|
)(settings: OSimpleSearch.Settings, fixQuery: Query.Fix, itemQuery: ItemQueryString) = {
|
||||||
import dsl._
|
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
|
backend.simpleSearch
|
||||||
.searchByString(settings)(fixQuery, itemQuery)
|
.searchByString(settings)(fixQuery, itemQuery)
|
||||||
.flatMap {
|
.flatMap {
|
||||||
case StringSearchResult.Success(items) =>
|
case StringSearchResult.Success(items) =>
|
||||||
Ok(
|
Ok(
|
||||||
items.fold(
|
items.fold(
|
||||||
Conversions.mkItemListFts,
|
convertFts,
|
||||||
Conversions.mkItemListWithTagsFts,
|
convertFtsFull,
|
||||||
Conversions.mkItemList,
|
Conversions.mkItemList,
|
||||||
Conversions.mkItemListWithTags
|
Conversions.mkItemListWithTags
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user