Skip to content

Commit

Permalink
Fixed bug in Query.stream.distance
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Dec 31, 2024
1 parent 5dde92d commit a3f32b1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions core/src/main/scala/lightdb/Query.scala
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,17 @@ case class Query[Doc <: Document[Doc], Model <: DocumentModel[Doc]](model: Model
from: Geo.Point,
sort: Boolean = true,
radius: Option[Distance] = None)
(implicit transaction: Transaction[Doc]): rapid.Stream[DistanceAndDoc[Doc]] =
apply(Conversion.Distance(f(model), from, sort, radius))
(implicit transaction: Transaction[Doc]): rapid.Stream[DistanceAndDoc[Doc]] = {
val field = f(model)
var q = Query.this
if (sort) {
q = q.clearSort.sort(Sort.ByDistance(field, from))
}
radius.foreach { r =>
q = q.filter(_ => field.distance(from, r))
}
rapid.Stream.force(q.distanceSearch(field, from, sort, radius).map(_.stream))
}
}

def toList(implicit transaction: Transaction[Doc]): Task[List[Doc]] = search.docs.flatMap(_.list)
Expand Down

0 comments on commit a3f32b1

Please sign in to comment.