21
21
22
22
import org .apache .lucene .search .Filter ;
23
23
import org .elasticsearch .common .inject .Inject ;
24
+ import org .elasticsearch .common .lucene .search .XBooleanFilter ;
24
25
import org .elasticsearch .common .xcontent .XContentParser ;
25
26
import org .elasticsearch .index .cache .filter .support .CacheKeyFilter ;
26
27
import org .elasticsearch .index .mapper .FieldMapper ;
29
30
import org .elasticsearch .index .search .geo .*;
30
31
31
32
import java .io .IOException ;
33
+ import java .util .ArrayList ;
34
+ import java .util .List ;
32
35
33
36
import static org .elasticsearch .index .query .support .QueryParsers .wrapSmartNameFilter ;
34
37
@@ -61,8 +64,7 @@ public Filter parse(QueryParseContext parseContext) throws IOException, QueryPar
61
64
String filterName = null ;
62
65
String currentFieldName = null ;
63
66
XContentParser .Token token ;
64
- boolean normalizeLon = true ;
65
- boolean normalizeLat = true ;
67
+ boolean normalize = true ;
66
68
67
69
String type = "memory" ;
68
70
@@ -151,23 +153,21 @@ public Filter parse(QueryParseContext parseContext) throws IOException, QueryPar
151
153
} else if ("_cache_key" .equals (currentFieldName ) || "_cacheKey" .equals (currentFieldName )) {
152
154
cacheKey = new CacheKeyFilter .Key (parser .text ());
153
155
} else if ("normalize" .equals (currentFieldName )) {
154
- normalizeLat = parser .booleanValue ();
155
- normalizeLon = parser .booleanValue ();
156
+ normalize = parser .booleanValue ();
156
157
} else if ("type" .equals (currentFieldName )) {
157
158
type = parser .text ();
158
159
} else {
159
- throw new QueryParsingException (parseContext .index (), "[qeo_bbox ] filter does not support [" + currentFieldName + "]" );
160
+ throw new QueryParsingException (parseContext .index (), "[geo_bbox ] filter does not support [" + currentFieldName + "]" );
160
161
}
161
162
}
162
163
}
163
164
164
- if (normalizeLat ) {
165
- topLeft .lat = GeoUtils .normalizeLat (topLeft .lat );
166
- bottomRight .lat = GeoUtils .normalizeLat (bottomRight .lat );
167
- }
168
- if (normalizeLon ) {
169
- topLeft .lon = GeoUtils .normalizeLon (topLeft .lon );
170
- bottomRight .lon = GeoUtils .normalizeLon (bottomRight .lon );
165
+ List <Range > ranges = null ;
166
+ if (normalize ) {
167
+ ranges = GeoUtils .normalizeRange (topLeft , bottomRight );
168
+ } else {
169
+ ranges = new ArrayList <Range >(1 );
170
+ ranges .add (new Range (topLeft , bottomRight ));
171
171
}
172
172
173
173
MapperService .SmartNameFieldMappers smartMappers = parseContext .smartFieldMappers (fieldName );
@@ -182,15 +182,20 @@ public Filter parse(QueryParseContext parseContext) throws IOException, QueryPar
182
182
183
183
fieldName = mapper .names ().indexName ();
184
184
185
- Filter filter ;
186
- if ("indexed" .equals (type )) {
187
- filter = IndexedGeoBoundingBoxFilter .create (topLeft , bottomRight , geoMapper );
188
- } else if ("memory" .equals (type )) {
189
- filter = new InMemoryGeoBoundingBoxFilter (topLeft , bottomRight , fieldName , parseContext .indexCache ().fieldData ());
190
- } else {
191
- throw new QueryParsingException (parseContext .index (), "geo bounding box type [" + type + "] not supported, either 'indexed' or 'memory' are allowed" );
185
+ XBooleanFilter boolFilter = new XBooleanFilter ();
186
+ for (Range r : ranges ) {
187
+ Filter f ;
188
+ if ("indexed" .equals (type )) {
189
+ f = IndexedGeoBoundingBoxFilter .create (topLeft , bottomRight , geoMapper );
190
+ } else if ("memory" .equals (type )) {
191
+ f = new InMemoryGeoBoundingBoxFilter (topLeft , bottomRight , fieldName , parseContext .indexCache ().fieldData ());
192
+ } else {
193
+ throw new QueryParsingException (parseContext .index (), "geo bounding box type [" + type + "] not supported, either 'indexed' or 'memory' are allowed" );
194
+ }
195
+ boolFilter .addShould (f );
192
196
}
193
197
198
+ Filter filter = boolFilter ;
194
199
if (cache ) {
195
200
filter = parseContext .cacheFilter (filter , cacheKey );
196
201
}
0 commit comments