add smart name filter wrapping for geo filters to automatically filter by type if as well if provided

This commit is contained in:
kimchy 2010-09-23 19:34:41 +02:00
parent 832914bf6d
commit 097071a9d2
4 changed files with 16 additions and 3 deletions

View File

@ -33,6 +33,9 @@ import org.elasticsearch.index.settings.IndexSettings;
import java.io.IOException;
/**
* The "fquery" filter is the same as the {@link QueryFilterParser} except that it allows also to
* associate a name with the query filter.
*
* @author kimchy (shay.banon)
*/
public class FQueryFilterParser extends AbstractIndexComponent implements XContentFilterParser {

View File

@ -35,6 +35,8 @@ import org.elasticsearch.index.settings.IndexSettings;
import java.io.IOException;
import static org.elasticsearch.index.query.support.QueryParsers.*;
/**
* @author kimchy (shay.banon)
*/
@ -148,6 +150,7 @@ public class GeoBoundingBoxFilterParser extends AbstractIndexComponent implement
}
MapperService mapperService = parseContext.mapperService();
FieldMapper mapper = mapperService.smartNameFieldMapper(latFieldName);
if (mapper == null) {
throw new QueryParsingException(index, "failed to find lat field [" + latFieldName + "]");
@ -161,7 +164,8 @@ public class GeoBoundingBoxFilterParser extends AbstractIndexComponent implement
lonFieldName = mapper.names().indexName();
GeoBoundingBoxFilter filter = new GeoBoundingBoxFilter(topLeft, bottomRight, latFieldName, lonFieldName, mapper.fieldDataType(), parseContext.indexCache().fieldData());
Filter filter = new GeoBoundingBoxFilter(topLeft, bottomRight, latFieldName, lonFieldName, mapper.fieldDataType(), parseContext.indexCache().fieldData());
filter = wrapSmartNameFilter(filter, parseContext.smartFieldMappers(latFieldName), parseContext);
if (filterName != null) {
parseContext.addNamedFilter(filterName, filter);
}

View File

@ -37,6 +37,8 @@ import org.elasticsearch.index.settings.IndexSettings;
import java.io.IOException;
import static org.elasticsearch.index.query.support.QueryParsers.*;
/**
* <pre>
* {
@ -167,7 +169,8 @@ public class GeoDistanceFilterParser extends AbstractIndexComponent implements X
}
lonFieldName = mapper.names().indexName();
GeoDistanceFilter filter = new GeoDistanceFilter(lat, lon, distance, geoDistance, latFieldName, lonFieldName, mapper.fieldDataType(), parseContext.indexCache().fieldData());
Filter filter = new GeoDistanceFilter(lat, lon, distance, geoDistance, latFieldName, lonFieldName, mapper.fieldDataType(), parseContext.indexCache().fieldData());
filter = wrapSmartNameFilter(filter, parseContext.smartFieldMappers(latFieldName), parseContext);
if (filterName != null) {
parseContext.addNamedFilter(filterName, filter);
}

View File

@ -37,6 +37,8 @@ import org.elasticsearch.index.settings.IndexSettings;
import java.io.IOException;
import java.util.List;
import static org.elasticsearch.index.query.support.QueryParsers.*;
/**
* <pre>
* {
@ -160,7 +162,8 @@ public class GeoPolygonFilterParser extends AbstractIndexComponent implements XC
}
lonFieldName = mapper.names().indexName();
GeoPolygonFilter filter = new GeoPolygonFilter(points.toArray(new GeoPolygonFilter.Point[points.size()]), latFieldName, lonFieldName, mapper.fieldDataType(), parseContext.indexCache().fieldData());
Filter filter = new GeoPolygonFilter(points.toArray(new GeoPolygonFilter.Point[points.size()]), latFieldName, lonFieldName, mapper.fieldDataType(), parseContext.indexCache().fieldData());
filter = wrapSmartNameFilter(filter, parseContext.smartFieldMappers(latFieldName), parseContext);
if (filterName != null) {
parseContext.addNamedFilter(filterName, filter);
}