blob: 0ac408a1313a5839b295e913a8f1b07096513f47 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
// 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 GeoLocationItem extends TermItem {
private Location location;
/**
*/
public GeoLocationItem(Location location) {
this(location, location.getAttribute());
if (! location.hasAttribute()) {
throw new IllegalArgumentException("missing attribute on location: "+location);
}
}
/**
*/
public GeoLocationItem(Location location, String indexName) {
super(indexName, false);
if (location.hasAttribute() && ! location.getAttribute().equals(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);
}
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();
}
@Override
public ItemType getItemType() {
return ItemType.GEO_LOCATION_TERM;
}
@Override
public String getName() {
return "GEO_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;
GeoLocationItem other = (GeoLocationItem) 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(location.backendString(), buffer);
}
@Override
public int getNumWords() {
return 1;
}
@Override
public boolean isStemmed() {
return true;
}
@Override
public boolean isWords() {
return false;
}
}
|