summaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2020-07-08 12:54:44 +0000
committerArne Juul <arnej@verizonmedia.com>2020-07-15 15:39:20 +0000
commitaacf9c9ccbcd558e58086ee657c5061e038a62f0 (patch)
tree2aaf596851c8f119344bde7ae9fce10c2bf0570e /container-search
parentb3669d86589a0123338fe75c192cf9c79d331c1b (diff)
preserve "no radius" aspect
Diffstat (limited to 'container-search')
-rw-r--r--container-search/abi-spec.json1
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/Location.java24
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/query/GeoLocationItem.java27
3 files changed, 33 insertions, 19 deletions
diff --git a/container-search/abi-spec.json b/container-search/abi-spec.json
index 98cc7c5165d..2a7bcb1a873 100644
--- a/container-search/abi-spec.json
+++ b/container-search/abi-spec.json
@@ -536,6 +536,7 @@
"methods": [
"public void <init>(com.yahoo.prelude.Location)",
"public void <init>(com.yahoo.prelude.Location, java.lang.String)",
+ "public com.yahoo.prelude.Location getLocation()",
"public java.lang.String getRawWord()",
"public com.yahoo.prelude.query.Item$ItemType getItemType()",
"public java.lang.String getName()",
diff --git a/container-search/src/main/java/com/yahoo/prelude/Location.java b/container-search/src/main/java/com/yahoo/prelude/Location.java
index dc98284df22..3d3eed3b3df 100644
--- a/container-search/src/main/java/com/yahoo/prelude/Location.java
+++ b/container-search/src/main/java/com/yahoo/prelude/Location.java
@@ -127,7 +127,7 @@ public class Location {
throw new IllegalArgumentException("n/s location must be in range [-90,+90]");
}
if (radius_in_degrees < 0) {
- pr = 512 * 1024 * 1024;
+ pr = -1;
}
x = px;
y = py;
@@ -142,7 +142,7 @@ public class Location {
throw new IllegalArgumentException("can only set geo circle once");
}
if (radius_in_units < 0) {
- throw new IllegalArgumentException("radius must be positive");
+ radius_in_units = -1;
}
x = px;
y = py;
@@ -247,11 +247,14 @@ public class Location {
}
}
- public Location clone() {
- return new Location(toString());
+ public String toString() {
+ return render(false);
+ }
+ public String backendString() {
+ return render(true);
}
- public String toString() {
+ private String render(boolean forBackend) {
StringBuilder ser = new StringBuilder();
if (attribute != null) {
ser.append(attribute).append(':');
@@ -275,7 +278,7 @@ public class Location {
if (dimensions == 2) {
ser.append(",").append(y);
}
- ser.append(",").append(r).
+ ser.append(",").append(forBackend ? backendRadius() : r).
append(",").append(tableId).
append(",").append(s).
append(",").append(replace);
@@ -362,11 +365,16 @@ public class Location {
/**
* Obtain circle radius (in degrees).
+ * Note that "no radius" or "infinite radius" is represented as -1.
* May only be called when isGeoCircle() returns true.
**/
public double degRadius() {
checkGeoCircle();
- return 0.000001 * r;
+ return (r < 0) ? -1.0 : (0.000001 * r);
+ }
+
+ private int backendRadius() {
+ return (r < 0) ? (512 * 1024 * 1024) : r;
}
/**
@@ -374,7 +382,7 @@ public class Location {
* For internal use.
*/
public int encode(ByteBuffer buffer) {
- byte[] loc = Utf8.toBytes(toString());
+ byte[] loc = Utf8.toBytes(backendString());
buffer.put(loc);
return loc.length;
}
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/GeoLocationItem.java b/container-search/src/main/java/com/yahoo/prelude/query/GeoLocationItem.java
index 8007bb823f2..1bf9cb041be 100644
--- a/container-search/src/main/java/com/yahoo/prelude/query/GeoLocationItem.java
+++ b/container-search/src/main/java/com/yahoo/prelude/query/GeoLocationItem.java
@@ -18,27 +18,34 @@ public class GeoLocationItem extends TermItem {
/**
*/
public GeoLocationItem(Location location) {
- super(location.getAttribute(), false);
- this.location = location.clone();
+ this(location, location.getAttribute());
if (! location.hasAttribute()) {
throw new IllegalArgumentException("missing attribute on location: "+location);
}
- location.setAttribute(null);
- setNormalizable(false);
}
/**
*/
public GeoLocationItem(Location location, String indexName) {
super(indexName, false);
- this.location = location.clone();
if (location.hasAttribute() && ! location.getAttribute().equals(indexName)) {
- throw new IllegalArgumentException("inconsistent attribute on location: "+location+" versus indexName: "+indexName);
+ throw new IllegalArgumentException("inconsistent attribute on location: "+location.getAttribute()+" versus indexName: "+indexName);
+ }
+ if (! location.isGeoCircle()) {
+ throw new IllegalArgumentException("GeoLocationItem only supports Geo Circles, got: "+location);
+ }
+ if (location.hasBoundingBox()) {
+ throw new IllegalArgumentException("GeoLocationItem does not support bounding box yet, got: "+location);
}
- location.setAttribute(null);
+ this.location = new Location(location.toString());
+ this.location.setAttribute(null); // keep this in indexName only
setNormalizable(false);
}
+ public Location getLocation() {
+ return location;
+ }
+
@Override
public String getRawWord() {
return stringValue();
@@ -51,12 +58,11 @@ public class GeoLocationItem extends TermItem {
@Override
public String getName() {
- return "LOCATION";
+ return "GEO_LOCATION";
}
@Override
public String stringValue() {
- location.setAttribute(null);
return location.toString();
}
@@ -80,14 +86,13 @@ public class GeoLocationItem extends TermItem {
@Override
public String getIndexedString() {
- location.setAttribute(null);
return location.toString();
}
@Override
protected void encodeThis(ByteBuffer buffer) {
super.encodeThis(buffer); // takes care of index bytes
- putString(getIndexedString(), buffer);
+ putString(location.backendString(), buffer);
}
@Override