Skip to content

Commit

Permalink
Updated Sort.BestMatch to support Ascending
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Dec 26, 2024
1 parent df14729 commit 58ae85b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
16 changes: 7 additions & 9 deletions core/src/main/scala/lightdb/Sort.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,31 @@ 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)
}

case class ByDistance[Doc <: Document[Doc], G <: Geo](field: Field[Doc, List[G]],
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)
}
}
5 changes: 4 additions & 1 deletion lucene/src/main/scala/lightdb/lucene/LuceneStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 58ae85b

Please sign in to comment.