polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [05/50] [abbrv] zest-qi4j git commit: some updates
Date Fri, 17 Apr 2015 16:45:52 GMT
some updates


Project: http://git-wip-us.apache.org/repos/asf/zest-qi4j/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-qi4j/commit/236d0ef9
Tree: http://git-wip-us.apache.org/repos/asf/zest-qi4j/tree/236d0ef9
Diff: http://git-wip-us.apache.org/repos/asf/zest-qi4j/diff/236d0ef9

Branch: refs/heads/ramtej-fb/spatial.queries
Commit: 236d0ef93cd8d91855b52cfbcc4040bff5730eea
Parents: b4e474d
Author: jj <juergen.jetmar@gmail.com>
Authored: Tue Jan 6 22:09:06 2015 +0100
Committer: jj <juergen.jetmar@gmail.com>
Committed: Tue Jan 6 22:09:06 2015 +0100

----------------------------------------------------------------------
 .../main/java/org/qi4j/api/geometry/TPoint.java |   2 +-
 .../test/indexing/AbstractSpatialQueryTest.java |  17 +--
 .../indexing/AbstractSpatialRegressionTest.java | 145 ++++++++++++++++---
 .../elasticsearch/ElasticSearchFinder.java      |  59 +-------
 .../ElasticSearchFinderSupport.java             |  12 +-
 .../elasticsearch/ElasticSearchIndexer.java     |   2 +-
 .../spatial/ElasticSearchSpatialFinder.java     |  44 +++++-
 .../SpatialFunctionsSupportMatrix.java          |   2 +-
 .../configuration/SpatialSupportMatrix.java     | 123 ----------------
 .../predicates/PredicateFinderSupport.java      |   2 +-
 .../functions/predicates/ST_DisjointV3.java     | 131 +++++++++++++++++
 .../ElasticSearchSpatialExtensionFinder.java    | 129 -----------------
 ...SearchSpatialRegressionQueryClusterTest.java |  92 ++++++++++++
 ...earchSpatialRegressionQueryVariant1Test.java |   3 -
 ...earchSpatialRegressionQueryVariant2Test.java |   3 -
 ...SearchConfigurationVariant2Backup.properties |  28 ++++
 ...archConfigurationVariant2_Backup_.properties |  28 ++++
 .../domain/openstreetmap/model/state/OSM.java   |   7 -
 .../domain/openstreetmap/model/MapEntity.java   |   7 -
 .../domain/openstreetmap/model/TagEntity.java   |   7 -
 .../OpenStreetMapDomainModelAssembler.java      |   7 -
 .../openstreetmap/model/state/Features.java     |   7 -
 .../openstreetmap/model/state/Identifiable.java |   7 -
 .../openstreetmap/model/state/Properties.java   |   7 -
 .../model/test/TestOpenStreetMapModel.java      |  26 ----
 25 files changed, 470 insertions(+), 427 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/core/api/src/main/java/org/qi4j/api/geometry/TPoint.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/qi4j/api/geometry/TPoint.java b/core/api/src/main/java/org/qi4j/api/geometry/TPoint.java
index 36b39f2..80b72d8 100644
--- a/core/api/src/main/java/org/qi4j/api/geometry/TPoint.java
+++ b/core/api/src/main/java/org/qi4j/api/geometry/TPoint.java
@@ -88,11 +88,11 @@ public interface TPoint extends HasNoArea, TGeometry {
         }
 
         public TPoint of(double x, double y, double z) {
-            self.geometryType().set(TGEOMETRY_TYPE.POINT);
             init();
             self.x(x); // JJ TODO use fluent DSL
             self.y(y);
             self.z(z);
+            self.geometryType().set(TGEOMETRY_TYPE.POINT);
             return self;
         }
 

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractSpatialQueryTest.java
----------------------------------------------------------------------
diff --git a/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractSpatialQueryTest.java b/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractSpatialQueryTest.java
index c5186f4..7bcc39d 100644
--- a/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractSpatialQueryTest.java
+++ b/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractSpatialQueryTest.java
@@ -32,6 +32,8 @@ public class AbstractSpatialQueryTest
                 extends AbstractAnyQueryTest
 {
 
+    private final String CRS_EPSG_4326 = "EPSG:4326";
+
     public interface MapFeature
 
     {
@@ -60,19 +62,12 @@ public class AbstractSpatialQueryTest
         module.entities(MapFeatureEntity.class);
 
         // internal values
-        module.values(Coordinate.class, TLinearRing.class);
-
-        // API values
-        module.values(TPoint.class, TLineString.class, TPolygon.class, TGeometry.class);
-
-        // internal values
-        // module.values( Coordinate.class, TLinearRing.class,TGeometry.class);
+        module.values(Coordinate.class, TLinearRing.class, TGeometry.class);
 
         // API values
-        // module.values(TPoint.class,TLineString.class, TPolygon.class); // , TFeature.class);
-
-
-
+        module.values(TPoint.class, TMultiPoint.class, TLineString.class, TPolygon.class, TMultiPolygon.class, TFeature.class, TFeatureCollection.class);
+        TGeometry tGeometry = module.forMixin(TGeometry.class).declareDefaults();
+        tGeometry.CRS().set(CRS_EPSG_4326);
 
     }
 

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractSpatialRegressionTest.java
----------------------------------------------------------------------
diff --git a/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractSpatialRegressionTest.java b/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractSpatialRegressionTest.java
index c3de7f6..74cf07a 100644
--- a/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractSpatialRegressionTest.java
+++ b/core/testsupport/src/main/java/org/qi4j/test/indexing/AbstractSpatialRegressionTest.java
@@ -1,29 +1,21 @@
 package org.qi4j.test.indexing;
 
 import org.junit.Ignore;
-import org.junit.Rule;
 import org.junit.Test;
 import org.qi4j.api.common.Optional;
-import org.qi4j.api.composite.Composite;
 import org.qi4j.api.entity.EntityBuilder;
 import org.qi4j.api.entity.EntityComposite;
 import org.qi4j.api.geometry.*;
-import org.qi4j.api.geometry.internal.TGeometry;
 import org.qi4j.api.property.Property;
 import org.qi4j.api.query.Query;
 import org.qi4j.api.query.QueryBuilder;
-import org.qi4j.api.query.grammar.ExpressionSpecification;
 import org.qi4j.api.query.grammar.OrderBy;
-import org.qi4j.api.query.grammar.extensions.spatial.predicate.ST_WithinSpecification;
 import org.qi4j.api.unitofwork.UnitOfWork;
 import org.qi4j.bootstrap.AssemblyException;
 import org.qi4j.bootstrap.ModuleAssembly;
-import org.qi4j.functional.Specification;
 import org.qi4j.spi.query.EntityFinderException;
-import org.qi4j.test.EntityTestAssembler;
 
-import java.util.HashMap;
-import java.util.Map;
+import java.util.Iterator;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -32,11 +24,11 @@ import static org.junit.Assume.assumeTrue;
 import static org.qi4j.api.geometry.TGeometryFactory.*;
 import static org.qi4j.api.geometry.TGeometryFactory.TLinearRing;
 import static org.qi4j.api.query.QueryExpressions.and;
+import static org.qi4j.api.query.QueryExpressions.not;
 import static org.qi4j.api.query.QueryExpressions.templateFor;
 import static org.qi4j.api.query.grammar.extensions.spatial.SpatialQueryExpressions.ST_Disjoint;
 import static org.qi4j.api.query.grammar.extensions.spatial.SpatialQueryExpressions.ST_GeometryFromText;
 import static org.qi4j.api.query.grammar.extensions.spatial.SpatialQueryExpressions.ST_Within;
-import static org.junit.Assume.*;
 
 /**
  * Created by jj on 21.12.14.
@@ -60,7 +52,7 @@ public abstract class AbstractSpatialRegressionTest
         @Optional Property<TFeatureCollection>  featurecollection();
     }
 
-    private TPoint      _TPoint,_TPoint2, _TPoint3;
+    private TPoint _TPoint1,_TPoint2, _TPoint3;
     private TMultiPoint _TMultiPoint;
     private TLineString _TLineString;
     private TPolygon    _TPolygon;
@@ -71,7 +63,7 @@ public abstract class AbstractSpatialRegressionTest
 
         System.out.println("########### Populating Values ############");
 
-        _TPoint = TPoint(module).lat(48.13905780942574).lon(11.57958984375)
+        _TPoint1 = TPoint(module).lat(48.13905780942574).lon(11.57958984375)
                 .geometry();
 
         _TPoint2 = TPoint(module).lat(48.145748).lon(11.567976)
@@ -131,8 +123,8 @@ public abstract class AbstractSpatialRegressionTest
 
             // TPoint
             {
-                EntityBuilder<SpatialRegressionEntity> pointBuilder = unitOfWork.newEntityBuilder(SpatialRegressionEntity.class, "Point");
-                pointBuilder.instance().point().set(_TPoint);
+                EntityBuilder<SpatialRegressionEntity> pointBuilder = unitOfWork.newEntityBuilder(SpatialRegressionEntity.class, "Point1");
+                pointBuilder.instance().point().set(_TPoint1);
                 pointBuilder.newInstance();
 
                 EntityBuilder<SpatialRegressionEntity> pointBuilder2 = unitOfWork.newEntityBuilder(SpatialRegressionEntity.class, "Point2");
@@ -205,7 +197,7 @@ public abstract class AbstractSpatialRegressionTest
         query.find();
         assertEquals(1, query.count());
         TPoint tPoint = query.iterator().next().point().get();
-        assertTrue(tPoint.compareTo(_TPoint) == 0);
+        assertTrue(tPoint.compareTo(_TPoint1) == 0);
         // assertSame
     }
 
@@ -229,7 +221,7 @@ public abstract class AbstractSpatialRegressionTest
         query.find();
         assertEquals(1, query.count());
         TPoint tPoint = query.iterator().next().point().get();
-        assertTrue(tPoint.compareTo(_TPoint) == 0);
+        assertTrue(tPoint.compareTo(_TPoint1) == 0);
 
         // Transform(module).from(tPoint).to("EPSG:4326");
     }
@@ -249,15 +241,124 @@ public abstract class AbstractSpatialRegressionTest
                                          10, TUnit.METER
                                         )
                         ))
-                .orderBy(templateFor(SpatialRegressionsValues.class).point(), _TPoint, OrderBy.Order.ASCENDING);
+                .orderBy(templateFor(SpatialRegressionsValues.class).point(), _TPoint1, OrderBy.Order.ASCENDING);
 
         assumeTrue(isExpressionSupported(query));
         query.find();
         assertEquals(query.count(), 1);
         TPoint tPoint = query.iterator().next().point().get();
-        assertTrue(tPoint.compareTo(_TPoint) == 0);
+        assertTrue(tPoint.compareTo(_TPoint1) == 0);
     }
 
+    @Test
+    public void script03a()
+    {
+        QueryBuilder<SpatialRegressionsValues> qb = this.module.newQueryBuilder(SpatialRegressionsValues.class);
+
+        Query<SpatialRegressionsValues> query = unitOfWork.newQuery(
+                qb
+                        .where(and(
+                                ST_Within
+                                        (
+                                                templateFor(SpatialRegressionsValues.class).point(),
+                                                TPoint(module).y(48.13905780941111).x(11.57958981111).geometry(),
+                                                10, TUnit.METER
+                                        )
+                                        ,
+                                ST_Within
+                                         (
+                                                templateFor(SpatialRegressionsValues.class).point(),
+                                                TPoint(module).y(48.13905780941111).x(11.57958981111).geometry(),
+                                                 5, TUnit.METER
+                                                )
+                                ))
+                        )
+                .orderBy(templateFor(SpatialRegressionsValues.class).point(), _TPoint1, OrderBy.Order.ASCENDING);
+
+        assumeTrue(isExpressionSupported(query));
+        query.find();
+        assertEquals(query.count(), 1);
+        TPoint tPoint = query.iterator().next().point().get();
+        assertTrue(tPoint.compareTo(_TPoint1) == 0);
+    }
+
+    @Test
+    public void script03b() {
+        QueryBuilder<SpatialRegressionsValues> qb = this.module.newQueryBuilder(SpatialRegressionsValues.class);
+
+        Query<SpatialRegressionsValues> query = unitOfWork.newQuery(
+                qb
+                        .where(and(
+                                ST_Within
+                                        (
+                                                templateFor(SpatialRegressionsValues.class).point(),
+                                                TPoint(module).y(48.13905780941111).x(11.57958981111).geometry(),
+                                                1000, TUnit.KILOMETER
+                                        )
+                                ,
+                                not(ST_Within
+                                        (
+                                                templateFor(SpatialRegressionsValues.class).point(),
+                                                TPoint(module).y(48.13905780941111).x(11.57958981111).geometry(),
+                                                1, TUnit.METER
+                                        ))
+                        ))
+        )
+        .orderBy(templateFor(SpatialRegressionsValues.class).point(), _TPoint1, OrderBy.Order.ASCENDING);
+
+        assumeTrue(isExpressionSupported(query));
+        query.find();
+        assertEquals(query.count(), 2);
+
+        Iterator<SpatialRegressionsValues> results = query.iterator();
+
+        // sorted ascending by distance
+        TPoint tPoint2 = results.next().point().get();
+        TPoint tPoint3 = results.next().point().get();
+
+        assertTrue(tPoint2.compareTo(_TPoint2) == 0);
+        assertTrue(tPoint3.compareTo(_TPoint3) == 0);
+    }
+
+    @Test
+    public void script03c() {
+        QueryBuilder<SpatialRegressionsValues> qb = this.module.newQueryBuilder(SpatialRegressionsValues.class);
+
+        Query<SpatialRegressionsValues> query = unitOfWork.newQuery(
+                qb
+                        .where(and(
+                                ST_Within
+                                        (
+                                                templateFor(SpatialRegressionsValues.class).point(),
+                                                TPoint(module).y(48.13905780941111).x(11.57958981111).geometry(),
+                                                1000, TUnit.KILOMETER
+                                        )
+                                ,
+                                not(ST_Within
+                                        (
+                                                templateFor(SpatialRegressionsValues.class).point(),
+                                                TPoint(module).y(48.13905780941111).x(11.57958981111).geometry(),
+                                                1, TUnit.METER
+                                        ))
+                        ))
+        )
+                .orderBy(templateFor(SpatialRegressionsValues.class).point(), _TPoint1, OrderBy.Order.DESCENDING);
+
+        assumeTrue(isExpressionSupported(query));
+        query.find();
+        assertEquals(query.count(), 2);
+
+        Iterator<SpatialRegressionsValues> results = query.iterator();
+
+        // sorted descending by distance
+        TPoint tPoint3 = results.next().point().get();
+        TPoint tPoint2 = results.next().point().get();
+
+        assertTrue(tPoint2.compareTo(_TPoint2) == 0);
+        assertTrue(tPoint3.compareTo(_TPoint3) == 0);
+    }
+
+
     @Ignore
     @Test
     public void script04()
@@ -274,13 +375,13 @@ public abstract class AbstractSpatialRegressionTest
                                          10,TUnit.METER
                                         )
                         ))
-                .orderBy(templateFor(SpatialRegressionsValues.class).point(), _TPoint, OrderBy.Order.ASCENDING);
+                .orderBy(templateFor(SpatialRegressionsValues.class).point(), _TPoint1, OrderBy.Order.ASCENDING);
 
         // assumeTrue(isExpressionSupported(query));
         query.find();
         assertEquals(query.count(), 1);
         TPoint tPoint = query.iterator().next().point().get();
-        assertTrue(tPoint.compareTo(_TPoint) == 0);
+        assertTrue(tPoint.compareTo(_TPoint1) == 0);
     }
 
     @Test
@@ -320,7 +421,7 @@ public abstract class AbstractSpatialRegressionTest
         assertEquals(1, query.count());
         assertEquals(query.count(), 1);
         TPoint tPoint = query.iterator().next().point().get();
-        assertTrue(tPoint.compareTo(_TPoint) == 0);
+        assertTrue(tPoint.compareTo(_TPoint1) == 0);
     }
 
     @Test
@@ -423,7 +524,7 @@ public abstract class AbstractSpatialRegressionTest
         query.find();
         assertEquals(4, query.count());
         TPoint tPoint = query.iterator().next().point().get();
-        assertTrue(tPoint.compareTo(_TPoint) == 0);
+        assertTrue(tPoint.compareTo(_TPoint1) == 0);
         // assertSame
     }
 

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchFinder.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchFinder.java b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchFinder.java
index 3082cac..dd204ea 100644
--- a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchFinder.java
+++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchFinder.java
@@ -51,6 +51,7 @@ import org.qi4j.index.elasticsearch.ElasticSearchFinderSupport.*;
 import org.qi4j.index.elasticsearch.extensions.spatial.ElasticSearchSpatialFinder;
 import org.qi4j.index.elasticsearch.extensions.spatial.functions.convert.ConvertFinderSupport;
 import org.qi4j.index.elasticsearch.extensions.spatial.functions.predicates.PredicateFinderSupport;
+import org.qi4j.index.elasticsearch.extensions.spatial.internal.InternalUtils;
 import org.qi4j.spi.query.EntityFinder;
 import org.qi4j.spi.query.EntityFinderException;
 import org.slf4j.Logger;
@@ -145,60 +146,16 @@ public interface ElasticSearchFinder
             }
             if( orderBySegments != null )
             {
-                try {
-                for( OrderBy order : orderBySegments )
-                {
-
-                    // System.out.println("OrderBy " + order);
-                    // System.out.println("Name " + order.property().toString()); // getClass().getTypeName());
-
-
-                   //  order.property().accessor().
-
-                            String typeName = Classes.typeOf(order.property().accessor()).getTypeName();
-                    //System.out.println(typeName);
-
-                    Type returnType = Classes.typeOf(order.property().accessor());
-                    Type propertyTypeAsType = GenericPropertyInfo.toPropertyType(returnType);
-
-
-                    //System.out.println(propertyTypeAsType.getTypeName());
-
+                for( OrderBy orderBySegment : orderBySegments ) {
 
-                        Class clazz = Class.forName(propertyTypeAsType.getTypeName());
-                        // if (clazz instanceof TGeometry)
-
-                        if (TGeometry.class.isAssignableFrom(clazz))
-                        {
-                            //System.out.println("Spatial Type");
-
-                            System.out.println("Order Type " + order.property().toString());
-
-                            // if (
-                            //    !TPoint.class.isAssignableFrom(clazz) ||
-                            //    !Mappings(support).onIndex(support.index()).andType(support.entitiesType()).isGeoPoint(order.property().toString())
-                            //   )
-                            //    throw new RuntimeException("OrderBy can only be done on properties of type TPoint.");
-
-                            GeoDistanceSortBuilder geoDistanceSortBuilder = new GeoDistanceSortBuilder(order.property().toString()); // "point"); // (order.property().toString());
-                            geoDistanceSortBuilder.point(order.getCentre().x(), order.getCentre().y());
-                           // geoDistanceSortBuilder.point(48.13905780941111, 11.57958981111);
-                            geoDistanceSortBuilder.order(order.order() == OrderBy.Order.ASCENDING ? SortOrder.ASC : SortOrder.DESC);
-                            //                 .addSort(geoDistanceSortBuilder.sortMode("min").order(SortOrder.ASC).geoDistance(GeoDistance.PLANE).unit(DistanceUnit.KILOMETERS))
-
-                            // geoDistanceSortBuilder.sortMode("min").geoDistance(GeoDistance.ARC).unit(DistanceUnit.KILOMETERS)
-
-                            request.addSort(geoDistanceSortBuilder.sortMode("max").geoDistance(GeoDistance.ARC).order( SortOrder.DESC));
-                        }
-
-                    else {
-                        request.addSort(order.property().toString(),
-                                order.order() == OrderBy.Order.ASCENDING ? SortOrder.ASC : SortOrder.DESC);
+                    if (COMPLEX_TYPE_SUPPORTS.get(InternalUtils.classOfPropertyType(orderBySegment.property())) != null) {
+                        COMPLEX_TYPE_SUPPORTS.get(InternalUtils.classOfPropertyType(orderBySegment.property())).support(module, support).orderBy(request, whereClause, orderBySegment, variables);
+                    } else {
+                        request.addSort(orderBySegment.property().toString(),
+                                orderBySegment.order() == OrderBy.Order.ASCENDING ? SortOrder.ASC : SortOrder.DESC);
                     }
                 }
-                } catch (ClassNotFoundException e) {
-                    e.printStackTrace();
-                }
+
             }
 
             // Log

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchFinderSupport.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchFinderSupport.java b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchFinderSupport.java
index ad08680..53c8d3d 100644
--- a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchFinderSupport.java
+++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchFinderSupport.java
@@ -18,11 +18,13 @@
 package org.qi4j.index.elasticsearch;
 
 import java.util.Map;
+
+import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.index.query.FilterBuilder;
-import org.qi4j.api.query.grammar.ComparisonSpecification;
-import org.qi4j.api.query.grammar.ContainsAllSpecification;
-import org.qi4j.api.query.grammar.ContainsSpecification;
-import org.qi4j.api.query.grammar.Variable;
+import org.qi4j.api.composite.Composite;
+import org.qi4j.api.query.grammar.*;
+import org.qi4j.api.structure.Module;
+import org.qi4j.functional.Specification;
 import org.qi4j.spi.query.EntityFinderException;
 
 
@@ -50,6 +52,7 @@ public final class ElasticSearchFinderSupport
 
     public static interface ComplexTypeSupport
     {
+        ComplexTypeSupport support(Module module, ElasticSearchSupport support);
 
         FilterBuilder comparison( ComparisonSpecification<?> spec, Map<String, Object> variables );
 
@@ -57,6 +60,7 @@ public final class ElasticSearchFinderSupport
 
         FilterBuilder containsAll( ContainsAllSpecification<?> spec, Map<String, Object> variables );
 
+        void orderBy(SearchRequestBuilder request,  Specification<Composite> whereClause, OrderBy orderBySegment, Map<String, Object> variables ) throws EntityFinderException;
     }
 
     private ElasticSearchFinderSupport()

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchIndexer.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchIndexer.java b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchIndexer.java
index 99335f3..fe969ba 100644
--- a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchIndexer.java
+++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/ElasticSearchIndexer.java
@@ -130,7 +130,7 @@ public interface ElasticSearchIndexer
                         case NEW:
                             LOGGER.trace( "Creating Entity State in Index: {}", changedState );
                             String newJson = toJSON(changedState, newStates, uow );
-                            // System.out.println("#Will index: {}  : " + newJson);
+                            System.out.println("#Will index: {}  : " + newJson);
                             LOGGER.trace( "Will index: {}", newJson );
                             index( bulkBuilder, changedState.identity().identity(), newJson );
                             break;

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/ElasticSearchSpatialFinder.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/ElasticSearchSpatialFinder.java b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/ElasticSearchSpatialFinder.java
index 5d1cfb1..af529fd 100644
--- a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/ElasticSearchSpatialFinder.java
+++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/ElasticSearchSpatialFinder.java
@@ -18,10 +18,18 @@ package org.qi4j.index.elasticsearch.extensions.spatial;
  * limitations under the License.
  */
 
+import org.elasticsearch.action.search.SearchRequestBuilder;
+import org.elasticsearch.common.geo.GeoDistance;
+import org.elasticsearch.common.unit.DistanceUnit;
 import org.elasticsearch.index.query.*;
+import org.elasticsearch.search.sort.GeoDistanceSortBuilder;
+import org.elasticsearch.search.sort.SortOrder;
+import org.qi4j.api.composite.Composite;
+import org.qi4j.api.geometry.TPoint;
 import org.qi4j.api.query.grammar.ComparisonSpecification;
 import org.qi4j.api.query.grammar.ContainsAllSpecification;
 import org.qi4j.api.query.grammar.ContainsSpecification;
+import org.qi4j.api.query.grammar.OrderBy;
 import org.qi4j.api.query.grammar.extensions.spatial.convert.SpatialConvertSpecification;
 import org.qi4j.api.query.grammar.extensions.spatial.predicate.SpatialPredicatesSpecification;
 import org.qi4j.api.structure.Module;
@@ -29,6 +37,8 @@ import org.qi4j.functional.Specification;
 import org.qi4j.index.elasticsearch.ElasticSearchSupport;
 import org.qi4j.index.elasticsearch.extensions.spatial.functions.convert.ConvertFinderSupport;
 import org.qi4j.index.elasticsearch.extensions.spatial.functions.predicates.PredicateFinderSupport;
+import org.qi4j.index.elasticsearch.extensions.spatial.internal.InternalUtils;
+import org.qi4j.index.elasticsearch.extensions.spatial.mappings.SpatialIndexMapper;
 import org.qi4j.spi.query.EntityFinderException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -105,6 +115,18 @@ public final class ElasticSearchSpatialFinder
             implements ElasticSearchFinderSupport.ComplexTypeSupport
     {
 
+        private Module module;
+        private ElasticSearchSupport support;
+
+        public ElasticSearchFinderSupport.ComplexTypeSupport support(Module module, ElasticSearchSupport support)
+        {
+            this.module  = module;
+            this.support = support;
+
+            return this;
+        }
+
+
         public FilterBuilder comparison( ComparisonSpecification<?> spec, Map<String, Object> variables )
         {
             throw new RuntimeException("Unsupported operation");
@@ -113,19 +135,37 @@ public final class ElasticSearchSpatialFinder
         public FilterBuilder contains( ContainsSpecification<?> spec, Map<String, Object> variables )
         {
             throw new RuntimeException("Unsupported operation");
-
         }
 
         public FilterBuilder containsAll( ContainsAllSpecification<?> spec, Map<String, Object> variables )
         {
             throw new RuntimeException("Unsupported operation");
         }
+
+        public void orderBy(SearchRequestBuilder request,  Specification<Composite> whereClause, OrderBy orderBySegment, Map<String, Object> variables ) throws EntityFinderException
+        {
+            if (!TPoint.class.isAssignableFrom(InternalUtils.classOfPropertyType(orderBySegment.property())))
+            {
+                throw new EntityFinderException("Ordering can only be done on TPoints.. TODO");
+            }
+
+            if (!SpatialIndexMapper.IndexMappingCache.isMappedAsGeoPoint(support.index(), support.entitiesType(), orderBySegment.property().toString()))
+            {
+                throw new EntityFinderException("OrderBy is only supported when GEO_POINT indexing is used");
+            }
+
+            GeoDistanceSortBuilder geoDistanceSortBuilder = new GeoDistanceSortBuilder(orderBySegment.property().toString());
+            geoDistanceSortBuilder.point(orderBySegment.getCentre().y(), orderBySegment.getCentre().x());
+
+            geoDistanceSortBuilder.order(orderBySegment.order() == OrderBy.Order.ASCENDING ? SortOrder.ASC : SortOrder.DESC);
+            request.addSort(geoDistanceSortBuilder.geoDistance(GeoDistance.SLOPPY_ARC).sortMode("avg").unit(DistanceUnit.METERS));
+        }
     }
 
 
 
 
-        private ElasticSearchSpatialFinder()
+     private ElasticSearchSpatialFinder()
     {
     }
 

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialFunctionsSupportMatrix.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialFunctionsSupportMatrix.java b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialFunctionsSupportMatrix.java
index 9750b2b..c51d31a 100644
--- a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialFunctionsSupportMatrix.java
+++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialFunctionsSupportMatrix.java
@@ -45,7 +45,7 @@ public class SpatialFunctionsSupportMatrix
         //supports(ST_WithinV2.class, propertyOf(AnyGeometry), filterOf(TPoint.class, TPolygon.class), disable(OrderBy), INDEXING_METHOD.TPOINT_AS_GEOSHAPE);
 
         // ST_Disjoint
-        supports(disable(ST_DisjointSpecification.class), propertyOf(AnyGeometry), filterOf(AnyGeometry), disable(OrderBy), SpatialConfiguration.INDEXING_METHOD.GEO_POINT);
+        supports(enable(ST_DisjointSpecification.class), propertyOf(AnyGeometry), filterOf(TPoint.class, TPolygon.class), enable(OrderBy), SpatialConfiguration.INDEXING_METHOD.GEO_POINT);
         supports(enable(ST_DisjointSpecification.class),  propertyOf(AnyGeometry), filterOf(TPoint.class, TPolygon.class), disable(OrderBy), SpatialConfiguration.INDEXING_METHOD.GEO_SHAPE);
 
 

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialSupportMatrix.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialSupportMatrix.java b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialSupportMatrix.java
deleted file mode 100644
index e805410..0000000
--- a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/configuration/SpatialSupportMatrix.java
+++ /dev/null
@@ -1,123 +0,0 @@
-package org.qi4j.index.elasticsearch.extensions.spatial.configuration;
-
-import com.google.common.collect.HashBasedTable;
-import com.google.common.collect.Table;
-import org.qi4j.api.geometry.TPoint;
-import org.qi4j.api.geometry.TPolygon;
-import org.qi4j.api.geometry.internal.TGeometry;
-import org.qi4j.api.query.grammar.ExpressionSpecification;
-import org.qi4j.index.elasticsearch.extensions.spatial.functions.predicates.ST_Disjoint;
-import org.qi4j.index.elasticsearch.extensions.spatial.functions.predicates.ST_Intersects;
-import org.qi4j.index.elasticsearch.extensions.spatial.functions.predicates.ST_WithinV2;
-import org.qi4j.index.elasticsearch.extensions.spatial.mappings.cache.MappingsCache;
-
-import java.lang.reflect.Array;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * Created by jj on 22.12.14.
- */
-public class SpatialSupportMatrix
-{
-
-    private Boolean OrderBy = true;
-    private Class<? extends TGeometry> AnyGeometry = TGeometry.class;
-    public static enum INDEX_MAPPING_POINT_METHOD {AS_GEO_POINT, AS_GEO_SHAPE}
-
-    private static final Table<Class, INDEX_MAPPING_POINT_METHOD, ConfigurationEntry> SPATIAL_SUPPORT_MATRIX = HashBasedTable.create();
-
-
-
-    {
-        // ST_Within
-        supports(ST_WithinV2.class, propertyOf(AnyGeometry), filterOf(TPoint.class, TPolygon.class), OrderBy, INDEX_MAPPING_POINT_METHOD.AS_GEO_POINT);
-        supports(ST_WithinV2.class, propertyOf(AnyGeometry), filterOf(TPoint.class, TPolygon.class), not(OrderBy), INDEX_MAPPING_POINT_METHOD.AS_GEO_SHAPE);
-
-        // ST_Disjoint
-        supports(not(ST_Disjoint.class), AnyGeometry, AnyGeometry, OrderBy, INDEX_MAPPING_POINT_METHOD.AS_GEO_POINT);
-        supports(ST_Disjoint.class, TGeometry.class, TGeometry.class, not(OrderBy), INDEX_MAPPING_POINT_METHOD.AS_GEO_SHAPE);
-
-        // ST_Intersects
-        supports(not(ST_Intersects.class), AnyGeometry, AnyGeometry, OrderBy, INDEX_MAPPING_POINT_METHOD.AS_GEO_POINT);
-        supports(not(ST_Intersects.class), TGeometry.class, TGeometry.class, not(OrderBy), INDEX_MAPPING_POINT_METHOD.AS_GEO_SHAPE);
-    }
-
-
-
-
-    {
-        supports(ST_WithinV2.class, TPoint.class, not(TPoint.class), OrderBy, INDEX_MAPPING_POINT_METHOD.AS_GEO_SHAPE);
-    }
-
-    private class ConfigurationEntry
-    {
-        private INDEX_MAPPING_POINT_METHOD method;
-        private Boolean orderBy;
-        private List<Class<? extends  TGeometry>> supportedPropertyGeometries = new LinkedList<>();
-        private List<Class<? extends  TGeometry>> supportedFilterGeometries = new LinkedList<>();
-
-        public ConfigurationEntry(Class<? extends  TGeometry>[] geometriesOfProperty, Class<? extends  TGeometry>[] geometriesOfFilter, Boolean orderBy, INDEX_MAPPING_POINT_METHOD method)
-        {
-            this.supportedPropertyGeometries = Arrays.asList(geometriesOfProperty);
-            this.supportedFilterGeometries   = Arrays.asList(geometriesOfFilter);
-            this.orderBy = orderBy;
-            this.method  = method;
-        }
-
-        public boolean isSupported( Class<? extends  TGeometry> geometryOfProperty, Class<? extends  TGeometry> geometryOfFilter, Boolean orderBy)
-        {
-            return false;
-        }
-    }
-
-
-    public boolean isSupported(Class expression, Class<? extends  TGeometry> geometryOfProperty,Class<? extends  TGeometry> geometryOfFilter, Boolean orderBy, INDEX_MAPPING_POINT_METHOD method )
-    {
-        if (SPATIAL_SUPPORT_MATRIX.contains(expression, method))
-            return SPATIAL_SUPPORT_MATRIX.get(expression, method).isSupported(geometryOfProperty, geometryOfFilter, orderBy);
-        else
-            return false;
-    }
-
-    private void supports (Class expression, Class<? extends  TGeometry> geometryOfProperty,Class<? extends  TGeometry> geometryOfFilter, Boolean orderBy, INDEX_MAPPING_POINT_METHOD method)
-    {
-        supports
-                (
-                 expression,
-                 (Class < ?extends TGeometry >[])Array.newInstance(geometryOfProperty, 1),
-                 (Class<? extends TGeometry>[]) Array.newInstance(geometryOfFilter, 1),
-                 orderBy, method
-                );
-    }
-
-    private void supports (Class expression, Class<? extends  TGeometry>[] geometriesOfProperty,Class<? extends  TGeometry>[] geometriesOfFilter, Boolean orderBy, INDEX_MAPPING_POINT_METHOD method)
-    {
-        SPATIAL_SUPPORT_MATRIX.put(expression, method, new ConfigurationEntry(geometriesOfProperty, geometriesOfFilter,orderBy, method));
-    }
-
-
-
-    private Class not(Class clazz)
-    {
-        return Object.class;
-    }
-
-    private Boolean not(Boolean bool)
-    {
-        return false;
-    }
-
-
-    private Class<? extends  TGeometry>[] filterOf(Class<? extends  TGeometry>... geometryOfFilters)
-    {
-        return geometryOfFilters;
-    }
-
-    private Class<? extends  TGeometry>[] propertyOf(Class<? extends  TGeometry>... geometryOfProperty)
-    {
-        return geometryOfProperty;
-    }
-}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/PredicateFinderSupport.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/PredicateFinderSupport.java b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/PredicateFinderSupport.java
index 3530c1c..2adcb64 100644
--- a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/PredicateFinderSupport.java
+++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/PredicateFinderSupport.java
@@ -31,7 +31,7 @@ public class PredicateFinderSupport implements ElasticSearchSpatialFinder.Spatia
     static
     {
         SPATIAL_PREDICATE_OPERATIONS.put(ST_WithinSpecification.class, new ST_Within());
-        SPATIAL_PREDICATE_OPERATIONS.put(ST_DisjointSpecification.class, new ST_DisjointV2());
+        SPATIAL_PREDICATE_OPERATIONS.put(ST_DisjointSpecification.class, new ST_DisjointV3());
         SPATIAL_PREDICATE_OPERATIONS.put(ST_IntersectsSpecification.class, new ST_Intersects());
     }
 

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/ST_DisjointV3.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/ST_DisjointV3.java b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/ST_DisjointV3.java
new file mode 100644
index 0000000..c89804d
--- /dev/null
+++ b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/functions/predicates/ST_DisjointV3.java
@@ -0,0 +1,131 @@
+package org.qi4j.index.elasticsearch.extensions.spatial.functions.predicates;
+
+import com.spatial4j.core.distance.DistanceUtils;
+import org.elasticsearch.common.geo.ShapeRelation;
+import org.elasticsearch.index.query.FilterBuilder;
+import org.elasticsearch.index.query.FilterBuilders;
+import org.elasticsearch.index.query.GeoPolygonFilterBuilder;
+import org.qi4j.api.geometry.TPoint;
+import org.qi4j.api.geometry.TPolygon;
+import org.qi4j.api.geometry.internal.TCircle;
+import org.qi4j.api.geometry.internal.TGeometry;
+import org.qi4j.api.query.grammar.extensions.spatial.predicate.ST_DisjointSpecification;
+import org.qi4j.api.query.grammar.extensions.spatial.predicate.ST_WithinSpecification;
+import org.qi4j.api.query.grammar.extensions.spatial.predicate.SpatialPredicatesSpecification;
+import org.qi4j.index.elasticsearch.extensions.spatial.internal.AbstractElasticSearchSpatialFunction;
+import org.qi4j.spi.query.EntityFinderException;
+
+import java.util.Map;
+
+import static org.elasticsearch.index.query.FilterBuilders.andFilter;
+import static org.elasticsearch.index.query.FilterBuilders.notFilter;
+import static org.elasticsearch.index.query.FilterBuilders.termFilter;
+
+/**
+ * Created by jj on 23.12.14.
+ */
+public class ST_DisjointV3 extends AbstractElasticSearchSpatialFunction implements PredicateFinderSupport.PredicateSpecification
+{
+    public void processSpecification(FilterBuilder filterBuilder,
+                                     SpatialPredicatesSpecification<?> spec,
+                                     Map<String, Object> variables)
+            throws EntityFinderException
+    {
+        TGeometry geomOfFilterProperty = resolveGeometry(filterBuilder, spec, module);
+
+        if (!isValid(spec))
+            throw new EntityFinderException(spec.getClass() + " expression invalid.");
+
+        if (!isMapped(spec.property()))
+            throw new EntityFinderException(spec.getClass() + " expression invalid. No spatial mapping available for property " + spec.property());
+
+        if (!isSupported(spec, geomOfFilterProperty))
+            throw new EntityFinderException(spec.getClass() + " expression unsupported by ElasticSearch. Pls specify a supported expression.");
+
+
+
+
+        /**
+         * When the geometry used in the ST_Within expression is of type TPoint and a distance is specified, e.g.
+         *
+         * TPoint point = TPoint(module).x(..).y(..);
+         * ST_Within (templateFor(x.class).propertyOfTypeTPoint(), point, 1, TUnit.METER)
+         *
+         * then a ES GeoDistanceFilter is used.
+         *
+         */
+        if (
+                isTPoint(geomOfFilterProperty) &&
+                        isMappedAsGeoPoint(spec.property()) &&
+                        ((ST_DisjointSpecification) spec).getDistance() > 0
+                )
+        {
+            addFilter(andFilter(notFilter(createGeoDistanceFilter
+                            (
+                                    spec.property().toString(),
+                                    (TPoint) verifyProjection(geomOfFilterProperty),
+                                    ((ST_DisjointSpecification) spec).getDistance(),
+                                    ((ST_DisjointSpecification) spec).getUnit()
+                            )), null),
+                    // )termFilter( "point.type", "point" )),
+                    filterBuilder
+            );
+        }
+
+
+
+
+        else if (isPropertyOfType(TPoint.class, spec.property()) && isMappedAsGeoShape(spec.property()))
+        {
+            if (geomOfFilterProperty instanceof TPolygon)
+            {
+                /**
+                 * This must not happen, but in case the expression is defined using WTK like :
+                 *
+                 * ST_Within (templateFor(x.class).propertyOfTypeTPoint(),
+                 *              POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5)),
+                 *              1, TUnit.METER) // <- This is invalid !!
+                 *
+                 * we have to check it here.
+                 *
+                 */
+                if (((ST_DisjointSpecification)spec).getDistance() > 0)
+                    throw new EntityFinderException("Invalid ST_Disjoint expression. A " + TPolygon.class.getSimpleName() + " can " +
+                            "not be combined with distance.");
+
+                TPolygon polygonFilter = (TPolygon)verifyProjection(geomOfFilterProperty);
+
+                GeoPolygonFilterBuilder geoPolygonFilterBuilder = FilterBuilders.geoPolygonFilter(spec.property().toString());
+
+                for (int i = 0; i < polygonFilter.shell().get().getNumPoints(); i++) {
+                    TPoint point = polygonFilter.shell().get().getPointN(i);
+                    geoPolygonFilterBuilder.addPoint(point.x(), point.y());
+                }
+                addFilter(notFilter(geoPolygonFilterBuilder), filterBuilder); // TODO NOT
+            }
+            else if (geomOfFilterProperty instanceof TPoint && ((ST_DisjointSpecification)spec).getDistance() > 0 )
+            {
+
+                double distanceMeters = convertDistanceToMeters(((ST_DisjointSpecification)spec).getDistance() , ((ST_DisjointSpecification)spec).getUnit());
+                System.out.println("Distance in Meters " + distanceMeters);
+                double distanceDegrees = DistanceUtils.dist2Degrees(distanceMeters, DistanceUtils.EARTH_MEAN_RADIUS_KM * 1000);
+                // This is a special case. We are using polygon substitution to support a circle. ATTENTION - this is just a approximation !!
+                TPoint circlePoint = (TPoint)verifyProjection(geomOfFilterProperty);
+                TCircle tCircle = module.newValueBuilder(TCircle.class).prototype().of(circlePoint, distanceDegrees);
+                TPolygon polygonizedCircleFilter = tCircle.polygonize(360);
+                addFilter(createShapeFilter(spec.property().toString(), polygonizedCircleFilter, ShapeRelation.DISJOINT), filterBuilder);
+            }
+
+
+        }
+        else
+        {
+            /**
+             * In all other cases we are using a shape filter.
+            */
+            addFilter(createShapeFilter(spec.property().toString(), geomOfFilterProperty, ShapeRelation.DISJOINT), filterBuilder);
+        }
+
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/index/ElasticSearchSpatialExtensionFinder.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/index/ElasticSearchSpatialExtensionFinder.java b/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/index/ElasticSearchSpatialExtensionFinder.java
deleted file mode 100644
index c1ec059..0000000
--- a/extensions/indexing-elasticsearch/src/main/java/org/qi4j/index/elasticsearch/extensions/spatial/index/ElasticSearchSpatialExtensionFinder.java
+++ /dev/null
@@ -1,129 +0,0 @@
-package org.qi4j.index.elasticsearch.extensions.spatial.index;
-
-/*
- * Copyright 2014 Jiri Jetmar.
- *
- * Licensed  under the  Apache License,  Version 2.0  (the "License");
- * you may not use  this file  except in  compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed  under the  License is distributed on an "AS IS" BASIS,
- * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
- * implied.
- *
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.elasticsearch.index.query.*;
-import org.qi4j.api.query.grammar.ComparisonSpecification;
-import org.qi4j.api.query.grammar.ContainsAllSpecification;
-import org.qi4j.api.query.grammar.ContainsSpecification;
-import org.qi4j.api.query.grammar.extensions.spatial.convert.SpatialConvertSpecification;
-import org.qi4j.api.query.grammar.extensions.spatial.predicate.SpatialPredicatesSpecification;
-import org.qi4j.api.structure.Module;
-import org.qi4j.functional.Specification;
-import org.qi4j.index.elasticsearch.ElasticSearchSupport;
-import org.qi4j.index.elasticsearch.extensions.spatial.functions.convert.ElasticSearchSpatialConvertFinderSupport;
-import org.qi4j.index.elasticsearch.extensions.spatial.functions.predicates.ElasticSearchSpatialPredicateFinderSupport;
-import org.qi4j.spi.query.EntityFinderException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.elasticsearch.index.query.FilterBuilders.geoShapeFilter;
-
-import org.qi4j.index.elasticsearch.ElasticSearchFinderSupport;
-
-public final class ElasticSearchSpatialExtensionFinder
-{
-
-    private static final Logger LOGGER = LoggerFactory.getLogger(ElasticSearchSpatialExtensionFinder.class);
-
-    private static final Map<Class<?>, SpatialQuerySpecSupport> SPATIAL_QUERY_EXPRESSIONS_CATALOG = new HashMap<>( 2 );
-
-    static
-    {
-        SPATIAL_QUERY_EXPRESSIONS_CATALOG.put(SpatialPredicatesSpecification.class, new ElasticSearchSpatialPredicateFinderSupport());
-        SPATIAL_QUERY_EXPRESSIONS_CATALOG.put(SpatialConvertSpecification.class, new ElasticSearchSpatialConvertFinderSupport());
-    }
-
-
-
-    public interface ModuleHelper {
-        void setModule(Module module, ElasticSearchSupport support);
-    }
-
-    public static interface SpatialQuerySpecSupport extends ModuleHelper
-    {
-        void processSpecification(FilterBuilder filterBuilder, Specification<?> spec, Map<String, Object> variables)  throws EntityFinderException;
-    }
-
-
-
-    public static class SpatialSpecSupport
-                implements  SpatialQuerySpecSupport {
-
-        Module module;
-        ElasticSearchSupport support;
-
-        public void setModule(Module module, ElasticSearchSupport support)
-        {
-            this.module  = module;
-            this.support = support;
-        }
-
-
-        public void processSpecification(FilterBuilder filterBuilder,
-                                              Specification<?> spec,
-                                              Map<String, Object> variables) {
-
-            SpatialQuerySpecSupport spatialQuerySpecSupport = SPATIAL_QUERY_EXPRESSIONS_CATALOG.get(spec.getClass().getSuperclass());
-            spatialQuerySpecSupport.setModule(module, support);
-
-            try {
-                spatialQuerySpecSupport.processSpecification(filterBuilder, spec, variables);
-
-            } catch (Exception _ex) {
-                _ex.printStackTrace();
-            }
-
-
-        }
-
-    }
-
-
-    public static class SpatialTypeSupport
-            implements ElasticSearchFinderSupport.ComplexTypeSupport
-    {
-
-        public FilterBuilder comparison( ComparisonSpecification<?> spec, Map<String, Object> variables )
-        {
-            return null;
-        }
-
-        public FilterBuilder contains( ContainsSpecification<?> spec, Map<String, Object> variables )
-        {
-            return null;
-        }
-
-        public FilterBuilder containsAll( ContainsAllSpecification<?> spec, Map<String, Object> variables )
-        {
-            return null;
-        }
-    }
-
-
-
-
-        private ElasticSearchSpatialExtensionFinder()
-    {
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialRegressionQueryClusterTest.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialRegressionQueryClusterTest.java b/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialRegressionQueryClusterTest.java
new file mode 100644
index 0000000..0ad7c1c
--- /dev/null
+++ b/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialRegressionQueryClusterTest.java
@@ -0,0 +1,92 @@
+package org.qi4j.index.elasticsearch.extension.spatial;
+
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.qi4j.api.common.Visibility;
+import org.qi4j.api.query.Query;
+import org.qi4j.bootstrap.AssemblyException;
+import org.qi4j.bootstrap.ModuleAssembly;
+import org.qi4j.index.elasticsearch.ElasticSearchConfiguration;
+import org.qi4j.index.elasticsearch.assembly.ESClusterIndexQueryAssembler;
+import org.qi4j.index.elasticsearch.assembly.ESFilesystemIndexQueryAssembler;
+import org.qi4j.index.elasticsearch.extensions.spatial.configuration.SpatialConfiguration;
+import org.qi4j.library.fileconfig.FileConfigurationOverride;
+import org.qi4j.library.fileconfig.FileConfigurationService;
+import org.qi4j.library.spatial.v2.assembly.TGeometryAssembler;
+import org.qi4j.test.EntityTestAssembler;
+import org.qi4j.test.indexing.AbstractSpatialRegressionTest;
+import org.qi4j.test.util.DelTreeAfter;
+
+import java.io.File;
+
+import static org.qi4j.test.util.Assume.assumeNoIbmJdk;
+
+/**
+ * Created by jj on 21.12.14.
+ */
+public class ElasticSearchSpatialRegressionQueryClusterTest
+        extends AbstractSpatialRegressionTest
+{
+    private static final File DATA_DIR = new File( "build/tmp/es-spatial-query-test" );
+    @Rule
+    public final DelTreeAfter delTreeAfter = new DelTreeAfter( DATA_DIR );
+
+    @BeforeClass
+    public static void beforeClass_IBMJDK()
+    {
+        assumeNoIbmJdk();
+    }
+
+    protected boolean isExpressionSupported(Query<?> expression)
+    {
+        return true;
+    }
+
+
+    @Override
+    public void assemble( ModuleAssembly module )
+            throws AssemblyException
+    {
+        super.assemble( module );
+
+        // Geometry support
+        new TGeometryAssembler().assemble(module);
+
+
+
+        // Config module
+        ModuleAssembly config = module.layer().module( "config" );
+        new EntityTestAssembler().assemble( config );
+
+        config.values(SpatialConfiguration.Configuration.class,
+                SpatialConfiguration.FinderConfiguration.class,
+                SpatialConfiguration.IndexerConfiguration.class,
+                SpatialConfiguration.IndexingMethod.class,
+                SpatialConfiguration.ProjectionSupport.class).
+                visibleIn(Visibility.application);
+
+        // Index/Query
+        new ESClusterIndexQueryAssembler().
+                withConfig(config, Visibility.layer).
+                identifiedBy("ElasticSearchConfigurationVariant1").
+                assemble(module);
+        ElasticSearchConfiguration esConfig = config.forMixin(ElasticSearchConfiguration.class).declareDefaults();
+        esConfig.indexNonAggregatedAssociations().set(Boolean.TRUE);
+        esConfig.indexPointMappingMethod().set(ElasticSearchConfiguration.INDEX_MAPPING_POINT_METHOD.GEO_POINT);
+
+
+        // FileConfig
+        FileConfigurationOverride override = new FileConfigurationOverride().
+                withData(new File(DATA_DIR, "qi4j-data")).
+                withLog(new File(DATA_DIR, "qi4j-logs")).
+                withTemporary(new File(DATA_DIR, "qi4j-temp"));
+        module.services(FileConfigurationService.class).
+                setMetaInfo(override);
+
+
+        config.services(FileConfigurationService.class)
+                // .identifiedBy("ElasticSearchConfigurationVariant1")
+                .setMetaInfo(override)
+                .visibleIn(Visibility.application);
+    }
+}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialRegressionQueryVariant1Test.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialRegressionQueryVariant1Test.java b/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialRegressionQueryVariant1Test.java
index 30e3a23..66cdc73 100644
--- a/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialRegressionQueryVariant1Test.java
+++ b/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialRegressionQueryVariant1Test.java
@@ -127,8 +127,5 @@ public class ElasticSearchSpatialRegressionQueryVariant1Test
                 // .identifiedBy("ElasticSearchConfigurationVariant1")
                 .setMetaInfo(override)
                 .visibleIn(Visibility.application);
-
-        // clear index mapping caches during junit testcases
-        // SpatialIndexMapper.IndexMappingCache.clear();
     }
 }

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialRegressionQueryVariant2Test.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialRegressionQueryVariant2Test.java b/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialRegressionQueryVariant2Test.java
index 45ece0d..322defa 100644
--- a/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialRegressionQueryVariant2Test.java
+++ b/extensions/indexing-elasticsearch/src/test/java/org/qi4j/index/elasticsearch/extension/spatial/ElasticSearchSpatialRegressionQueryVariant2Test.java
@@ -127,8 +127,5 @@ public class ElasticSearchSpatialRegressionQueryVariant2Test
                 // .identifiedBy("ElasticSearchConfigurationVariant1")
                 .setMetaInfo(override)
                 .visibleIn(Visibility.application);
-
-        // clear index mapping caches during junit testcases
-        // SpatialIndexMapper.IndexMappingCache.clear();
     }
 }

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/extensions/indexing-elasticsearch/src/test/resources/ElasticSearchConfigurationVariant2Backup.properties
----------------------------------------------------------------------
diff --git a/extensions/indexing-elasticsearch/src/test/resources/ElasticSearchConfigurationVariant2Backup.properties b/extensions/indexing-elasticsearch/src/test/resources/ElasticSearchConfigurationVariant2Backup.properties
new file mode 100644
index 0000000..3837000
--- /dev/null
+++ b/extensions/indexing-elasticsearch/src/test/resources/ElasticSearchConfigurationVariant2Backup.properties
@@ -0,0 +1,28 @@
+spatial = { \
+  \
+  Enabled : true, \
+  \
+  Indexer=\
+   { \
+    Method=\
+      { \
+        Type      = "GEO_SHAPE", \
+        Precision = 1m, \
+      }, \
+    Projection=\
+      { \
+        ConversionEnabled  = true, \
+        ConversionAccuracy = 1m, \
+      }, \
+   }, \
+  \
+  \
+  Finder=\
+    { \
+    Projection=\
+      { \
+        ConversionEnabled  = true, \
+        ConversionAccuracy = 1m, \
+      } \
+    } \
+  }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/extensions/indexing-elasticsearch/src/test/resources/ElasticSearchConfigurationVariant2_Backup_.properties
----------------------------------------------------------------------
diff --git a/extensions/indexing-elasticsearch/src/test/resources/ElasticSearchConfigurationVariant2_Backup_.properties b/extensions/indexing-elasticsearch/src/test/resources/ElasticSearchConfigurationVariant2_Backup_.properties
new file mode 100644
index 0000000..3837000
--- /dev/null
+++ b/extensions/indexing-elasticsearch/src/test/resources/ElasticSearchConfigurationVariant2_Backup_.properties
@@ -0,0 +1,28 @@
+spatial = { \
+  \
+  Enabled : true, \
+  \
+  Indexer=\
+   { \
+    Method=\
+      { \
+        Type      = "GEO_SHAPE", \
+        Precision = 1m, \
+      }, \
+    Projection=\
+      { \
+        ConversionEnabled  = true, \
+        ConversionAccuracy = 1m, \
+      }, \
+   }, \
+  \
+  \
+  Finder=\
+    { \
+    Projection=\
+      { \
+        ConversionEnabled  = true, \
+        ConversionAccuracy = 1m, \
+      } \
+    } \
+  }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/samples/openstreetmap/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/OSM.java
----------------------------------------------------------------------
diff --git a/samples/openstreetmap/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/OSM.java b/samples/openstreetmap/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/OSM.java
deleted file mode 100644
index c249034..0000000
--- a/samples/openstreetmap/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/OSM.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.qi4j.sample.spatial.domain.openstreetmap.model.state;
-
-/**
- * Created by jj on 01.12.14.
- */
-public interface OSM {
-}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/MapEntity.java
----------------------------------------------------------------------
diff --git a/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/MapEntity.java b/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/MapEntity.java
deleted file mode 100644
index fe7ddfa..0000000
--- a/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/MapEntity.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.qi4j.sample.spatial.domain.openstreetmap.model;
-
-/**
- * Created by jj on 28.11.14.
- */
-public interface MapEntity {
-}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/TagEntity.java
----------------------------------------------------------------------
diff --git a/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/TagEntity.java b/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/TagEntity.java
deleted file mode 100644
index 1175663..0000000
--- a/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/TagEntity.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.qi4j.sample.spatial.domain.openstreetmap.model;
-
-/**
- * Created by jj on 28.11.14.
- */
-public class TagEntity {
-}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/assembly/OpenStreetMapDomainModelAssembler.java
----------------------------------------------------------------------
diff --git a/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/assembly/OpenStreetMapDomainModelAssembler.java b/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/assembly/OpenStreetMapDomainModelAssembler.java
deleted file mode 100644
index 0c5661f..0000000
--- a/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/assembly/OpenStreetMapDomainModelAssembler.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.qi4j.sample.spatial.domain.openstreetmap.model.assembly;
-
-/**
- * Created by jj on 28.11.14.
- */
-public class OpenStreetMapDomainModelAssembler {
-}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Features.java
----------------------------------------------------------------------
diff --git a/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Features.java b/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Features.java
deleted file mode 100644
index b6c5908..0000000
--- a/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Features.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.qi4j.sample.spatial.domain.openstreetmap.model.state;
-
-/**
- * Created by jj on 28.11.14.
- */
-public interface Features {
-}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Identifiable.java
----------------------------------------------------------------------
diff --git a/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Identifiable.java b/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Identifiable.java
deleted file mode 100644
index 763cc9d..0000000
--- a/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Identifiable.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.qi4j.sample.spatial.domain.openstreetmap.model.state;
-
-/**
- * Created by jj on 28.11.14.
- */
-public interface Identifiable {
-}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Properties.java
----------------------------------------------------------------------
diff --git a/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Properties.java b/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Properties.java
deleted file mode 100644
index 9dca43d..0000000
--- a/samples/spatial/src/main/java/org/qi4j/sample/spatial/domain/openstreetmap/model/state/Properties.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.qi4j.sample.spatial.domain.openstreetmap.model.state;
-
-/**
- * Created by jj on 28.11.14.
- */
-public interface Properties {
-}

http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/236d0ef9/samples/spatial/src/test/java/org/qi4j/sample/spatial/domain/openstreetmap/model/test/TestOpenStreetMapModel.java
----------------------------------------------------------------------
diff --git a/samples/spatial/src/test/java/org/qi4j/sample/spatial/domain/openstreetmap/model/test/TestOpenStreetMapModel.java b/samples/spatial/src/test/java/org/qi4j/sample/spatial/domain/openstreetmap/model/test/TestOpenStreetMapModel.java
deleted file mode 100644
index c220823..0000000
--- a/samples/spatial/src/test/java/org/qi4j/sample/spatial/domain/openstreetmap/model/test/TestOpenStreetMapModel.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package org.qi4j.sample.spatial.domain.openstreetmap.model.test;
-
-import org.junit.Test;
-import org.qi4j.bootstrap.AssemblyException;
-import org.qi4j.bootstrap.ModuleAssembly;
-import org.qi4j.sample.spatial.domain.openstreetmap.model.assembly.OpenStreetMapDomainModelAssembler;
-import org.qi4j.test.AbstractQi4jTest;
-
-/**
- * Created by jj on 28.11.14.
- */
-public class TestOpenStreetMapModel extends AbstractQi4jTest {
-
-    @Override
-    public void assemble( ModuleAssembly module )
-            throws AssemblyException
-    {
-        new OpenStreetMapDomainModelAssembler().assemble(module);
-    }
-
-    @Test
-    public void foo()
-    {
-        System.out.println("foo");
-    }
-}


Mime
View raw message