diff options
author | Arne Juul <arnej@verizonmedia.com> | 2020-07-07 11:31:00 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2020-07-15 15:39:19 +0000 |
commit | 570ede74b98309d245d960592acf69185f11749f (patch) | |
tree | d338d01b153ac0e27f47ba5e2959713b8dffb61c /container-search/src/main/java/com/yahoo | |
parent | 0093a1340d19eb6aeb668eff9e9013767984ad8e (diff) |
add LocationItem query item
Diffstat (limited to 'container-search/src/main/java/com/yahoo')
-rw-r--r-- | container-search/src/main/java/com/yahoo/prelude/query/LocationItem.java | 105 |
1 files changed, 105 insertions, 0 deletions
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; + } + +} |