18
18
*/
19
19
package org .elasticsearch .index .mapper ;
20
20
21
- import org .apache .lucene .document .Field ;
22
21
import org .apache .lucene .document .LatLonShape ;
23
- import org .apache .lucene .geo .Line ;
24
- import org .apache .lucene .geo .Polygon ;
25
- import org .apache .lucene .index .IndexableField ;
26
22
import org .elasticsearch .common .Explicit ;
27
23
import org .elasticsearch .common .geo .GeometryParser ;
28
24
import org .elasticsearch .common .geo .builders .ShapeBuilder ;
29
25
import org .elasticsearch .common .settings .Settings ;
30
- import org .elasticsearch .geo .geometry .Circle ;
31
26
import org .elasticsearch .geo .geometry .Geometry ;
32
- import org .elasticsearch .geo .geometry .GeometryCollection ;
33
- import org .elasticsearch .geo .geometry .GeometryVisitor ;
34
- import org .elasticsearch .geo .geometry .LinearRing ;
35
- import org .elasticsearch .geo .geometry .MultiLine ;
36
- import org .elasticsearch .geo .geometry .MultiPoint ;
37
- import org .elasticsearch .geo .geometry .MultiPolygon ;
38
- import org .elasticsearch .geo .geometry .Point ;
39
27
import org .elasticsearch .index .query .VectorGeoShapeQueryProcessor ;
40
28
41
- import java .util .ArrayList ;
42
- import java .util .Arrays ;
43
-
44
29
/**
45
30
* FieldMapper for indexing {@link LatLonShape}s.
46
31
* <p>
@@ -80,12 +65,14 @@ public GeoShapeFieldMapper build(BuilderContext context) {
80
65
protected void setupFieldType (BuilderContext context ) {
81
66
super .setupFieldType (context );
82
67
83
- GeometryParser geometryParser = new GeometryParser (orientation == ShapeBuilder .Orientation .RIGHT , coerce (context ).value (),
84
- ignoreZValue ().value ());
68
+ GeoShapeFieldType fieldType = (GeoShapeFieldType )fieldType ();
69
+ boolean orientation = fieldType .orientation == ShapeBuilder .Orientation .RIGHT ;
70
+
71
+ GeometryParser geometryParser = new GeometryParser (orientation , coerce (context ).value (), ignoreZValue ().value ());
85
72
86
- (( GeoShapeFieldType ) fieldType ()) .setGeometryIndexer (new GeoShapeIndexer (orientation == ShapeBuilder . Orientation . RIGHT ));
87
- (( GeoShapeFieldType ) fieldType ()) .setGeometryParser ( (parser , mapper ) -> geometryParser .parse (parser ));
88
- (( GeoShapeFieldType ) fieldType ()) .setGeometryQueryBuilder (new VectorGeoShapeQueryProcessor ());
73
+ fieldType .setGeometryIndexer (new GeoShapeIndexer (orientation , fieldType . name () ));
74
+ fieldType .setGeometryParser ( (parser , mapper ) -> geometryParser .parse (parser ));
75
+ fieldType .setGeometryQueryBuilder (new VectorGeoShapeQueryProcessor ());
89
76
}
90
77
}
91
78
@@ -107,11 +94,6 @@ public GeoShapeFieldType clone() {
107
94
public String typeName () {
108
95
return CONTENT_TYPE ;
109
96
}
110
-
111
- @ Override
112
- protected Indexer <Geometry , Geometry > geometryIndexer () {
113
- return new GeoShapeIndexer (orientation == ShapeBuilder .Orientation .RIGHT );
114
- }
115
97
}
116
98
117
99
public GeoShapeFieldMapper (String simpleName , MappedFieldType fieldType , MappedFieldType defaultFieldType ,
@@ -127,103 +109,6 @@ public GeoShapeFieldType fieldType() {
127
109
return (GeoShapeFieldType ) super .fieldType ();
128
110
}
129
111
130
- @ Override
131
- protected void indexShape (ParseContext context , Geometry luceneShape ) {
132
- luceneShape .visit (new LuceneGeometryIndexer (context ));
133
- }
134
-
135
- private class LuceneGeometryIndexer implements GeometryVisitor <Void , RuntimeException > {
136
- private ParseContext context ;
137
-
138
- private LuceneGeometryIndexer (ParseContext context ) {
139
- this .context = context ;
140
- }
141
-
142
- @ Override
143
- public Void visit (Circle circle ) {
144
- throw new IllegalArgumentException ("invalid shape type found [Circle] while indexing shape" );
145
- }
146
-
147
- @ Override
148
- public Void visit (GeometryCollection <?> collection ) {
149
- for (Geometry geometry : collection ) {
150
- geometry .visit (this );
151
- }
152
- return null ;
153
- }
154
-
155
- @ Override
156
- public Void visit (org .elasticsearch .geo .geometry .Line line ) {
157
- indexFields (context , LatLonShape .createIndexableFields (name (), new Line (line .getLats (), line .getLons ())));
158
- return null ;
159
- }
160
-
161
- @ Override
162
- public Void visit (LinearRing ring ) {
163
- throw new IllegalArgumentException ("invalid shape type found [LinearRing] while indexing shape" );
164
- }
165
-
166
- @ Override
167
- public Void visit (MultiLine multiLine ) {
168
- for (org .elasticsearch .geo .geometry .Line line : multiLine ) {
169
- visit (line );
170
- }
171
- return null ;
172
- }
173
-
174
- @ Override
175
- public Void visit (MultiPoint multiPoint ) {
176
- for (Point point : multiPoint ) {
177
- visit (point );
178
- }
179
- return null ;
180
- }
181
-
182
- @ Override
183
- public Void visit (MultiPolygon multiPolygon ) {
184
- for (org .elasticsearch .geo .geometry .Polygon polygon : multiPolygon ) {
185
- visit (polygon );
186
- }
187
- return null ;
188
- }
189
-
190
- @ Override
191
- public Void visit (Point point ) {
192
- indexFields (context , LatLonShape .createIndexableFields (name (), point .getLat (), point .getLon ()));
193
- return null ;
194
- }
195
-
196
- @ Override
197
- public Void visit (org .elasticsearch .geo .geometry .Polygon polygon ) {
198
- indexFields (context , LatLonShape .createIndexableFields (name (), toLucenePolygon (polygon )));
199
- return null ;
200
- }
201
-
202
- @ Override
203
- public Void visit (org .elasticsearch .geo .geometry .Rectangle r ) {
204
- Polygon p = new Polygon (new double []{r .getMinLat (), r .getMinLat (), r .getMaxLat (), r .getMaxLat (), r .getMinLat ()},
205
- new double []{r .getMinLon (), r .getMaxLon (), r .getMaxLon (), r .getMinLon (), r .getMinLon ()});
206
- indexFields (context , LatLonShape .createIndexableFields (name (), p ));
207
- return null ;
208
- }
209
- }
210
-
211
- public static Polygon toLucenePolygon (org .elasticsearch .geo .geometry .Polygon polygon ) {
212
- Polygon [] holes = new Polygon [polygon .getNumberOfHoles ()];
213
- for (int i = 0 ; i <holes .length ; i ++) {
214
- holes [i ] = new Polygon (polygon .getHole (i ).getLats (), polygon .getHole (i ).getLons ());
215
- }
216
- return new Polygon (polygon .getPolygon ().getLats (), polygon .getPolygon ().getLons (), holes );
217
- }
218
-
219
- private void indexFields (ParseContext context , Field [] fields ) {
220
- ArrayList <IndexableField > flist = new ArrayList <>(Arrays .asList (fields ));
221
- createFieldNamesField (context , flist );
222
- for (IndexableField f : flist ) {
223
- context .doc ().add (f );
224
- }
225
- }
226
-
227
112
@ Override
228
113
protected String contentType () {
229
114
return CONTENT_TYPE ;
0 commit comments