move spatial4j and jts to be optional dependencies

allowing data and client nodes to work without them, disabling shapes if needed
This commit is contained in:
Shay Banon 2012-09-01 00:05:49 +02:00
parent e66bd4359a
commit 6c3847b0a9
8 changed files with 175 additions and 29 deletions

View File

@ -157,6 +157,7 @@
<artifactId>spatial4j</artifactId> <artifactId>spatial4j</artifactId>
<version>0.2</version> <version>0.2</version>
<scope>compile</scope> <scope>compile</scope>
<optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
@ -164,6 +165,7 @@
<artifactId>jts</artifactId> <artifactId>jts</artifactId>
<version>1.12</version> <version>1.12</version>
<scope>compile</scope> <scope>compile</scope>
<optional>true</optional>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>xerces</groupId> <groupId>xerces</groupId>

View File

@ -1,10 +1,31 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you 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.
*/
package org.elasticsearch.common.geo; package org.elasticsearch.common.geo;
import com.spatial4j.core.shape.Shape; import com.spatial4j.core.shape.Shape;
import com.spatial4j.core.shape.jts.JtsGeometry; import com.spatial4j.core.shape.jts.JtsGeometry;
import com.spatial4j.core.shape.jts.JtsPoint; import com.spatial4j.core.shape.jts.JtsPoint;
import com.spatial4j.core.shape.simple.RectangleImpl; import com.spatial4j.core.shape.simple.RectangleImpl;
import com.vividsolutions.jts.geom.*; import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LinearRing;
import org.elasticsearch.ElasticSearchParseException; import org.elasticsearch.ElasticSearchParseException;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -16,9 +37,9 @@ import java.util.Locale;
/** /**
* Parsers which supports reading {@link Shape}s in GeoJSON format from a given * Parsers which supports reading {@link Shape}s in GeoJSON format from a given
* {@link XContentParser}. * {@link XContentParser}.
* * <p/>
* An example of the format used for polygons: * An example of the format used for polygons:
* * <p/>
* { * {
* "type": "Polygon", * "type": "Polygon",
* "coordinates": [ * "coordinates": [
@ -26,7 +47,7 @@ import java.util.Locale;
* [100.0, 1.0], [100.0, 0.0] ] * [100.0, 1.0], [100.0, 0.0] ]
* ] * ]
* } * }
* * <p/>
* Note, currently MultiPolygon and GeometryCollections are not supported * Note, currently MultiPolygon and GeometryCollections are not supported
*/ */
public class GeoJSONShapeParser { public class GeoJSONShapeParser {
@ -157,7 +178,7 @@ public class GeoJSONShapeParser {
/** /**
* Node used to represent a tree of coordinates. * Node used to represent a tree of coordinates.
* * <p/>
* Can either be a leaf node consisting of a Coordinate, or a parent with children * Can either be a leaf node consisting of a Coordinate, or a parent with children
*/ */
private static class CoordinateNode { private static class CoordinateNode {

View File

@ -1,9 +1,28 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you 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.
*/
package org.elasticsearch.common.geo; package org.elasticsearch.common.geo;
import com.spatial4j.core.shape.*; import com.spatial4j.core.shape.Rectangle;
import com.spatial4j.core.shape.Shape;
import com.spatial4j.core.shape.jts.JtsGeometry; import com.spatial4j.core.shape.jts.JtsGeometry;
import com.vividsolutions.jts.geom.*; import com.vividsolutions.jts.geom.*;
import com.vividsolutions.jts.geom.Point;
import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -11,9 +30,9 @@ import java.io.IOException;
/** /**
* Serializes {@link Shape} instances into GeoJSON format * Serializes {@link Shape} instances into GeoJSON format
* * <p/>
* Example of the format used for points: * Example of the format used for points:
* * <p/>
* { "type": "Point", "coordinates": [100.0, 0.0] } * { "type": "Point", "coordinates": [100.0, 0.0] }
*/ */
public class GeoJSONShapeSerializer { public class GeoJSONShapeSerializer {

View File

@ -1,3 +1,22 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you 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.
*/
package org.elasticsearch.common.geo; package org.elasticsearch.common.geo;
import com.spatial4j.core.shape.Point; import com.spatial4j.core.shape.Point;

View File

@ -1,3 +1,22 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you 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.
*/
package org.elasticsearch.common.geo; package org.elasticsearch.common.geo;
import java.util.Locale; import java.util.Locale;

View File

@ -0,0 +1,56 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you 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.
*/
package org.elasticsearch.common.geo;
import com.spatial4j.core.shape.simple.PointImpl;
import com.vividsolutions.jts.geom.GeometryFactory;
/**
*/
public class ShapesAvailability {
public static final boolean SPATIAL4J_AVAILABLE;
public static final boolean JTS_AVAILABLE;
static {
boolean xSPATIAL4J_AVAILABLE;
try {
new PointImpl(0, 0);
xSPATIAL4J_AVAILABLE = true;
} catch (Throwable t) {
xSPATIAL4J_AVAILABLE = false;
}
SPATIAL4J_AVAILABLE = xSPATIAL4J_AVAILABLE;
boolean xJTS_AVAILABLE;
try {
new GeometryFactory();
xJTS_AVAILABLE = true;
} catch (Throwable t) {
xJTS_AVAILABLE = false;
}
JTS_AVAILABLE = xJTS_AVAILABLE;
}
private ShapesAvailability() {
}
}

View File

@ -25,6 +25,7 @@ import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.geo.ShapesAvailability;
import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
@ -70,7 +71,7 @@ public class DocumentMapperParser extends AbstractIndexComponent {
public DocumentMapperParser(Index index, @IndexSettings Settings indexSettings, AnalysisService analysisService) { public DocumentMapperParser(Index index, @IndexSettings Settings indexSettings, AnalysisService analysisService) {
super(index, indexSettings); super(index, indexSettings);
this.analysisService = analysisService; this.analysisService = analysisService;
typeParsers = new MapBuilder<String, Mapper.TypeParser>() MapBuilder<String, Mapper.TypeParser> typeParsersBuilder = new MapBuilder<String, Mapper.TypeParser>()
.put(ByteFieldMapper.CONTENT_TYPE, new ByteFieldMapper.TypeParser()) .put(ByteFieldMapper.CONTENT_TYPE, new ByteFieldMapper.TypeParser())
.put(ShortFieldMapper.CONTENT_TYPE, new ShortFieldMapper.TypeParser()) .put(ShortFieldMapper.CONTENT_TYPE, new ShortFieldMapper.TypeParser())
.put(IntegerFieldMapper.CONTENT_TYPE, new IntegerFieldMapper.TypeParser()) .put(IntegerFieldMapper.CONTENT_TYPE, new IntegerFieldMapper.TypeParser())
@ -85,9 +86,13 @@ public class DocumentMapperParser extends AbstractIndexComponent {
.put(ObjectMapper.CONTENT_TYPE, new ObjectMapper.TypeParser()) .put(ObjectMapper.CONTENT_TYPE, new ObjectMapper.TypeParser())
.put(ObjectMapper.NESTED_CONTENT_TYPE, new ObjectMapper.TypeParser()) .put(ObjectMapper.NESTED_CONTENT_TYPE, new ObjectMapper.TypeParser())
.put(MultiFieldMapper.CONTENT_TYPE, new MultiFieldMapper.TypeParser()) .put(MultiFieldMapper.CONTENT_TYPE, new MultiFieldMapper.TypeParser())
.put(GeoPointFieldMapper.CONTENT_TYPE, new GeoPointFieldMapper.TypeParser()) .put(GeoPointFieldMapper.CONTENT_TYPE, new GeoPointFieldMapper.TypeParser());
.put(GeoShapeFieldMapper.CONTENT_TYPE, new GeoShapeFieldMapper.TypeParser())
.immutableMap(); if (ShapesAvailability.JTS_AVAILABLE) {
typeParsersBuilder.put(GeoShapeFieldMapper.CONTENT_TYPE, new GeoShapeFieldMapper.TypeParser());
}
typeParsers = typeParsersBuilder.immutableMap();
rootTypeParsers = new MapBuilder<String, Mapper.TypeParser>() rootTypeParsers = new MapBuilder<String, Mapper.TypeParser>()
.put(SizeFieldMapper.NAME, new SizeFieldMapper.TypeParser()) .put(SizeFieldMapper.NAME, new SizeFieldMapper.TypeParser())

View File

@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.geo.ShapesAvailability;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.query.*; import org.elasticsearch.index.query.*;
@ -74,7 +75,9 @@ public class IndicesQueriesRegistry {
addQueryParser(queryParsers, new FuzzyLikeThisFieldQueryParser()); addQueryParser(queryParsers, new FuzzyLikeThisFieldQueryParser());
addQueryParser(queryParsers, new WrapperQueryParser()); addQueryParser(queryParsers, new WrapperQueryParser());
addQueryParser(queryParsers, new IndicesQueryParser(clusterService)); addQueryParser(queryParsers, new IndicesQueryParser(clusterService));
if (ShapesAvailability.JTS_AVAILABLE) {
addQueryParser(queryParsers, new GeoShapeQueryParser()); addQueryParser(queryParsers, new GeoShapeQueryParser());
}
this.queryParsers = ImmutableMap.copyOf(queryParsers); this.queryParsers = ImmutableMap.copyOf(queryParsers);
Map<String, FilterParser> filterParsers = Maps.newHashMap(); Map<String, FilterParser> filterParsers = Maps.newHashMap();
@ -93,7 +96,9 @@ public class IndicesQueriesRegistry {
addFilterParser(filterParsers, new GeoDistanceRangeFilterParser()); addFilterParser(filterParsers, new GeoDistanceRangeFilterParser());
addFilterParser(filterParsers, new GeoBoundingBoxFilterParser()); addFilterParser(filterParsers, new GeoBoundingBoxFilterParser());
addFilterParser(filterParsers, new GeoPolygonFilterParser()); addFilterParser(filterParsers, new GeoPolygonFilterParser());
if (ShapesAvailability.JTS_AVAILABLE) {
addFilterParser(filterParsers, new GeoShapeFilterParser()); addFilterParser(filterParsers, new GeoShapeFilterParser());
}
addFilterParser(filterParsers, new QueryFilterParser()); addFilterParser(filterParsers, new QueryFilterParser());
addFilterParser(filterParsers, new FQueryFilterParser()); addFilterParser(filterParsers, new FQueryFilterParser());
addFilterParser(filterParsers, new BoolFilterParser()); addFilterParser(filterParsers, new BoolFilterParser());