-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(dsl): Support 'geoDistance' query #211
Conversation
@@ -108,6 +108,74 @@ object ElasticQuery { | |||
final def filter(queries: ElasticQuery[Any]*): BoolQuery[Any] = | |||
Bool[Any](filter = queries.toList, must = Nil, mustNot = Nil, should = Nil, boost = None, minimumShouldMatch = None) | |||
|
|||
/** | |||
* Constructs an instance of [[zio.elasticsearch.query.GeoDistanceQuery]] using the specified parameters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use Constructs a type-safe instance of...
?
* | ||
* @param field | ||
* the type-safe field for which query is specified for | ||
* @param longitudeAndLatitude |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of this name.
GeoDistance(field = field, point = Left((longitude, latitude))) | ||
|
||
/** | ||
* Constructs an instance of [[zio.elasticsearch.query.GeoDistanceQuery]] using the specified parameters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use type-safe here as well?
* @param field | ||
* the type-safe field for which query is specified for | ||
* @param longitudeAndLatitude | ||
* longitude and latitude of desired point written as string(e.g. "40,31") or geo hash (e.g. "drm3btev3e86") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing " " between as string
and (e.g. ...)
.
* @param field | ||
* the field for which query is specified for | ||
* @param longitudeAndLatitude | ||
* longitude and latitude of desired point written as string(e.g. "40,31") or geo hash (e.g. "drm3btev3e86") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing " " between as string
and (e.g. ...)
.
/** | ||
* sets the `distanceType` parameter for the [[zio.elasticsearch.query.GeoDistanceQuery]] | ||
* | ||
* Defines how to compute the distance. Can either be [[zio.elasticsearch.query.DistanceType.Arc]] (default), or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check this and you can use a similar format.
|
||
def distanceType(value: DistanceType): GeoDistanceQuery[S] = self.copy(distanceType = Some(value)) | ||
|
||
private def getPointJson: (String, Json) = point match { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move this to paramsToJson
if it's used only once. Also, no need for a method.
@@ -833,6 +836,48 @@ object ElasticQuerySpec extends ZIOSpecDefault { | |||
) | |||
) | |||
) | |||
}, | |||
test("geoDistance") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep this sorted.
test("bool")
...
test("exists")
...
test("geoDistance")
...
test("match")
test("matchAll")
...
@@ -2324,6 +2369,112 @@ object ElasticQuerySpec extends ZIOSpecDefault { | |||
assert(queryWithBoost.toJson)(equalTo(expectedWithBoost.toJson)) && | |||
assert(queryWithCaseInsensitive.toJson)(equalTo(expectedWithCaseInsensitive.toJson)) && | |||
assert(queryWithAllParams.toJson)(equalTo(expectedWithAllParams.toJson)) | |||
}, | |||
test("geoDistance") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
|} | ||
|""".stripMargin | ||
|
||
assert(query.toJson)(equalTo(expected.toJson)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are missing &&
here.
a2ad8ab
to
c919276
Compare
* @param field | ||
* the type-safe field for which query is specified for | ||
* @param longitude | ||
* longitude of desired point |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...of the desired point.
* @param longitude | ||
* longitude of desired point | ||
* @param latitude | ||
* latitude of desired point |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of the desired point.
* @param field | ||
* the field for which query is specified for | ||
* @param longitude | ||
* longitude of desired point |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for every place in this file.
|
||
package zio.elasticsearch.query | ||
|
||
final case class Distance(distanceValue: Double, distanceUnit: DistanceUnit) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be private[elasticsearch]?
* [[zio.elasticsearch.query.DistanceUnit]]. | ||
* | ||
* @param value | ||
* the [[Double]] value for a non-negative real number used for distance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just: a non-negative number...
|
||
/** | ||
* Sets the `distanceType` parameter for the [[zio.elasticsearch.query.GeoDistanceQuery]]. | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove empty line.
* @param unit | ||
* the [[zio.elasticsearch.query.DistanceUnit]] in which we want to represent the distance | ||
* @return | ||
* a new instance of the [[zio.elasticsearch.query.GeoDistanceQuery]] with the score value set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...with the distance
..??
* - [[zio.elasticsearch.query.DistanceType.Arc]]: Default algorithm | ||
* - [[zio.elasticsearch.query.DistanceType.Plane]]: Faster, but inaccurate on long distances and close to the poles | ||
* @return | ||
* a new instance of the [[zio.elasticsearch.query.GeoDistanceQuery]] with the score value set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
score
value or distanceType
value?
* @param value | ||
* the [[String]] value to represent the name field | ||
* @return | ||
* a new instance of the [[zio.elasticsearch.query.GeoDistanceQuery]] with the score value set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe apply everywhere "...enriched with the paramName
param."
distance: Option[Distance] = None, | ||
distanceType: Option[DistanceType] = None, | ||
queryName: Option[String] = None, | ||
validationMethod: Option[ValidationMethod] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have predefined values here?
import zio.elasticsearch.FieldAccessorBuilder | ||
import zio.schema.{DeriveSchema, Schema} | ||
|
||
case class Location(lat: Double, lon: Double) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use final
here.
val queryWithName = | ||
geoDistance(TestDocument.stringField, 20.0, 21.1).name("name") | ||
val queryWithValidationMethod = | ||
geoDistance(TestDocument.stringField, 20.0, 21.1).validationMethod(IgnoreMalformed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add queryWithAllParams
.
Summary:
geo-distance
queryResolves geoDistanceQuery in #91