diff --git a/core/src/main/scala/lightdb/Sort.scala b/core/src/main/scala/lightdb/Sort.scala index 764d5f8..4e361d2 100644 --- a/core/src/main/scala/lightdb/Sort.scala +++ b/core/src/main/scala/lightdb/Sort.scala @@ -7,19 +7,21 @@ import lightdb.spatial.Geo trait Sort object Sort { - case object BestMatch extends Sort + case class BestMatch(direction: SortDirection = SortDirection.Descending) extends Sort { + def direction(direction: SortDirection): BestMatch = copy(direction = direction) + def ascending: BestMatch = direction(SortDirection.Ascending) + def asc: BestMatch = direction(SortDirection.Ascending) + def descending: BestMatch = direction(SortDirection.Descending) + def desc: BestMatch = direction(SortDirection.Descending) + } case object IndexOrder extends Sort case class ByField[Doc <: Document[Doc], F](field: Field[Doc, F], direction: SortDirection = SortDirection.Ascending) extends Sort { def direction(direction: SortDirection): ByField[Doc, F] = copy(direction = direction) - def ascending: ByField[Doc, F] = direction(SortDirection.Ascending) - def asc: ByField[Doc, F] = direction(SortDirection.Ascending) - def descending: ByField[Doc, F] = direction(SortDirection.Descending) - def desc: ByField[Doc, F] = direction(SortDirection.Descending) } @@ -27,13 +29,9 @@ object Sort { from: Geo.Point, direction: SortDirection = SortDirection.Ascending) extends Sort { def direction(direction: SortDirection): ByDistance[Doc, G] = copy(direction = direction) - def ascending: ByDistance[Doc, G] = direction(SortDirection.Ascending) - def asc: ByDistance[Doc, G] = direction(SortDirection.Ascending) - def descending: ByDistance[Doc, G] = direction(SortDirection.Descending) - def desc: ByDistance[Doc, G] = direction(SortDirection.Descending) } } \ No newline at end of file diff --git a/lucene/src/main/scala/lightdb/lucene/LuceneStore.scala b/lucene/src/main/scala/lightdb/lucene/LuceneStore.scala index 5df3bca..85155ba 100644 --- a/lucene/src/main/scala/lightdb/lucene/LuceneStore.scala +++ b/lucene/src/main/scala/lightdb/lucene/LuceneStore.scala @@ -498,7 +498,10 @@ class LuceneStore[Doc <: Document[Doc], Model <: DocumentModel[Doc]](name: Strin private def sort2SortField(sort: Sort): SortField = { sort match { - case Sort.BestMatch => SortField.FIELD_SCORE + case Sort.BestMatch(direction) => direction match { + case SortDirection.Descending => SortField.FIELD_SCORE + case SortDirection.Ascending => new SortField(null, SortField.Type.SCORE, true) + } case Sort.IndexOrder => SortField.FIELD_DOC case Sort.ByField(field, dir) => val fieldSortName = s"${field.name}Sort"