From 097071a9d20f08e96dea5b2a72e15d3be2a1ecf6 Mon Sep 17 00:00:00 2001 From: kimchy Date: Thu, 23 Sep 2010 19:34:41 +0200 Subject: [PATCH] add smart name filter wrapping for geo filters to automatically filter by type if as well if provided --- .../index/query/xcontent/FQueryFilterParser.java | 3 +++ .../index/query/xcontent/GeoBoundingBoxFilterParser.java | 6 +++++- .../index/query/xcontent/GeoDistanceFilterParser.java | 5 ++++- .../index/query/xcontent/GeoPolygonFilterParser.java | 5 ++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FQueryFilterParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FQueryFilterParser.java index 2550336a2eb..c85a171fc2e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FQueryFilterParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/FQueryFilterParser.java @@ -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 { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoBoundingBoxFilterParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoBoundingBoxFilterParser.java index d4fa64479b6..5939431f150 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoBoundingBoxFilterParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoBoundingBoxFilterParser.java @@ -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); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoDistanceFilterParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoDistanceFilterParser.java index ee273b2969b..f7e46bbbf1c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoDistanceFilterParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoDistanceFilterParser.java @@ -37,6 +37,8 @@ import org.elasticsearch.index.settings.IndexSettings; import java.io.IOException; +import static org.elasticsearch.index.query.support.QueryParsers.*; + /** *
  * {
@@ -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);
         }
diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoPolygonFilterParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoPolygonFilterParser.java
index 6e97a59e250..d78f670334b 100644
--- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoPolygonFilterParser.java
+++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/GeoPolygonFilterParser.java
@@ -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.*;
+
 /**
  * 
  * {
@@ -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);
         }