aboutsummaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2020-07-07 11:31:00 +0000
committerArne Juul <arnej@verizonmedia.com>2020-07-15 15:39:19 +0000
commit570ede74b98309d245d960592acf69185f11749f (patch)
treed338d01b153ac0e27f47ba5e2959713b8dffb61c /container-search
parent0093a1340d19eb6aeb668eff9e9013767984ad8e (diff)
add LocationItem query item
Diffstat (limited to 'container-search')
-rw-r--r--container-search/abi-spec.json24
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/query/LocationItem.java105
2 files changed, 129 insertions, 0 deletions
diff --git a/container-search/abi-spec.json b/container-search/abi-spec.json
index fcbe23aeb61..8728e525f88 100644
--- a/container-search/abi-spec.json
+++ b/container-search/abi-spec.json
@@ -805,6 +805,30 @@
"public static final com.yahoo.prelude.query.Limit POSITIVE_INFINITY"
]
},
+ "com.yahoo.prelude.query.LocationItem": {
+ "superClass": "com.yahoo.prelude.query.TermItem",
+ "interfaces": [],
+ "attributes": [
+ "public"
+ ],
+ "methods": [
+ "public void <init>(com.yahoo.prelude.Location)",
+ "public void <init>(com.yahoo.prelude.Location, java.lang.String)",
+ "public java.lang.String getRawWord()",
+ "public com.yahoo.prelude.query.Item$ItemType getItemType()",
+ "public java.lang.String getName()",
+ "public java.lang.String stringValue()",
+ "public void setValue(java.lang.String)",
+ "public int hashCode()",
+ "public boolean equals(java.lang.Object)",
+ "public java.lang.String getIndexedString()",
+ "protected void encodeThis(java.nio.ByteBuffer)",
+ "public int getNumWords()",
+ "public boolean isStemmed()",
+ "public boolean isWords()"
+ ],
+ "fields": []
+ },
"com.yahoo.prelude.query.MarkerWordItem": {
"superClass": "com.yahoo.prelude.query.WordItem",
"interfaces": [],
diff --git a/container-search/src/main/java/com/yahoo/prelude/query/LocationItem.java b/container-search/src/main/java/com/yahoo/prelude/query/LocationItem.java
new file mode 100644
index 00000000000..cf45712088b
--- /dev/null
+++ b/container-search/src/main/java/com/yahoo/prelude/query/LocationItem.java
@@ -0,0 +1,105 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.prelude.query;
+
+import com.yahoo.prelude.Location;
+import java.nio.ByteBuffer;
+
+
+/**
+ * This represents a geo-location for matching.
+ * Note that this won't produce summary fields.
+ *
+ * @author arnej
+ */
+public class LocationItem extends TermItem {
+
+ private Location location;
+
+ /**
+ */
+ public LocationItem(Location location) {
+ super(location.getAttribute(), false);
+ this.location = location;
+ if (! location.hasAttribute()) {
+ throw new IllegalArgumentException("missing attribute on location: "+location);
+ }
+ setNormalizable(false);
+ }
+
+ /**
+ */
+ public LocationItem(Location location, String indexName) {
+ super(indexName, false);
+ this.location = location;
+ if (location.hasAttribute() && ! location.getAttribute().equals(indexName)) {
+ throw new IllegalArgumentException("inconsistent attribute on location: "+location+" versus indexName: "+indexName);
+ }
+ this.location.setAttribute(indexName);
+ setNormalizable(false);
+ }
+
+ @Override
+ public String getRawWord() {
+ return stringValue();
+ }
+
+ @Override
+ public ItemType getItemType() {
+ return ItemType.LOCATION_TERM;
+ }
+
+ @Override
+ public String getName() {
+ return "LOCATION";
+ }
+
+ @Override
+ public String stringValue() {
+ return location.toString();
+ }
+
+ @Override
+ public void setValue(String value) {
+ throw new UnsupportedOperationException("Cannot setValue("+value+") on "+getName());
+ }
+
+ @Override
+ public int hashCode() {
+ return super.hashCode() + 199 * location.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if ( ! super.equals(object)) return false;
+ LocationItem other = (LocationItem) object; // Ensured by superclass
+ if ( ! location.equals(other.location)) return false;
+ return true;
+ }
+
+ @Override
+ public String getIndexedString() {
+ return location.toString();
+ }
+
+ @Override
+ protected void encodeThis(ByteBuffer buffer) {
+ super.encodeThis(buffer); // takes care of index bytes
+ putString(getIndexedString(), buffer);
+ }
+
+ @Override
+ public int getNumWords() {
+ return 1;
+ }
+
+ @Override
+ public boolean isStemmed() {
+ return true;
+ }
+
+ @Override
+ public boolean isWords() {
+ return false;
+ }
+
+}