diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/src/main/java/ai/vespa/client/dsl/GeoLocation.java | 44 | ||||
-rw-r--r-- | client/src/main/java/ai/vespa/client/dsl/Q.java | 14 | ||||
-rw-r--r-- | client/src/test/groovy/ai/vespa/client/dsl/QTest.groovy | 12 |
3 files changed, 70 insertions, 0 deletions
diff --git a/client/src/main/java/ai/vespa/client/dsl/GeoLocation.java b/client/src/main/java/ai/vespa/client/dsl/GeoLocation.java new file mode 100644 index 00000000000..c0d8fabc42f --- /dev/null +++ b/client/src/main/java/ai/vespa/client/dsl/GeoLocation.java @@ -0,0 +1,44 @@ +package ai.vespa.client.dsl; + +import org.apache.commons.text.StringEscapeUtils; + +public class GeoLocation extends QueryChain { + + private String fieldName; + private Double longitude; + private Double latitude; + private String radius; + + public GeoLocation(String fieldName, Double longitude, Double latitude, String radius) { + this.fieldName = fieldName; + this.longitude = longitude; + this.latitude = latitude; + this.radius = radius; + this.nonEmpty = true; + } + + @Override + boolean hasPositiveSearchField(String fieldName) { + return this.fieldName.equals(fieldName); + } + + @Override + boolean hasPositiveSearchField(String fieldName, Object value) { + return false; + } + + @Override + boolean hasNegativeSearchField(String fieldName) { + return false; + } + + @Override + boolean hasNegativeSearchField(String fieldName, Object value) { + return false; + } + + @Override + public String toString() { + return Text.format("geoLocation(%s, %f, %f, \"%s\")", fieldName, longitude, latitude, StringEscapeUtils.escapeJava(radius)); + } +} diff --git a/client/src/main/java/ai/vespa/client/dsl/Q.java b/client/src/main/java/ai/vespa/client/dsl/Q.java index 7637f76f095..2d957dcfb92 100644 --- a/client/src/main/java/ai/vespa/client/dsl/Q.java +++ b/client/src/main/java/ai/vespa/client/dsl/Q.java @@ -169,4 +169,18 @@ public final class Q { public static WeakAnd weakand(String field, Query query) { return new WeakAnd(field, query); } + + /** + * GeoLocation geo locatoin + * https://docs.vespa.ai/en/reference/query-language-reference.html#geoLocation + * + * @param field the field + * @param longitude longitude + * @param latitude latitude + * @param radius a string specifying the radius and it's unit + * @return the geo-location query + */ + public static GeoLocation geoLocation(String field, Double longitude, Double latitude, String radius) { + return new GeoLocation(field, longitude, latitude, radius); + } } diff --git a/client/src/test/groovy/ai/vespa/client/dsl/QTest.groovy b/client/src/test/groovy/ai/vespa/client/dsl/QTest.groovy index d1560937fef..e07e5d6cefc 100644 --- a/client/src/test/groovy/ai/vespa/client/dsl/QTest.groovy +++ b/client/src/test/groovy/ai/vespa/client/dsl/QTest.groovy @@ -244,6 +244,18 @@ class QTest extends Specification { q == """yql=select * from sd1 where weakAnd(f1, f1 contains "v1", f2 contains "v2") and ([{"scoreThreshold":0.13}]weakAnd(f3, f1 contains "v1", f2 contains "v2"));""" } + def "geo location"() { + given: + def q = Q.select("*") + .from("sd1") + .where("a").contains("b").and(Q.geoLocation("taiwan", 25.105497, 121.597366, "200km")) + .semicolon() + .build() + + expect: + q == """yql=select * from sd1 where a contains "b" and geoLocation(taiwan, 25.105497, 121.597366, "200km");""" + } + def "rank with only query"() { given: def q = Q.select("*") |