Skip to content

Commit

Permalink
Update plugin for elasticsearch 1.4.4. Add shape orientation in geo m…
Browse files Browse the repository at this point in the history
…apping
  • Loading branch information
Clément Tourrière committed Apr 2, 2015
1 parent c09bb46 commit 51f4456
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</parent>

<properties>
<elasticsearch.version>1.4.2</elasticsearch.version>
<elasticsearch.version>1.4.4</elasticsearch.version>
<geotools.version>12.1</geotools.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static class Names {
public static final String TREE_LEVELS = "tree_levels";
public static final String TREE_PRESISION = "precision";
public static final String DISTANCE_ERROR_PCT = "distance_error_pct";
public static final String ORIENTATION = "orientation";
public static final String STRATEGY = "strategy";
public static final String BOOST_PRECISION = "boost_precision";
public static final String WKB = "wkb";
Expand All @@ -70,6 +71,7 @@ public static class Defaults {
public static final int GEOHASH_LEVELS = GeoUtils.geoHashLevelsForPrecision("50m");
public static final int QUADTREE_LEVELS = GeoUtils.quadTreeLevelsForPrecision("50m");
public static final double DISTANCE_ERROR_PCT = 0.025d;
public static final ShapeBuilder.Orientation ORIENTATION = ShapeBuilder.Orientation.RIGHT;
public static final double BOOST_PRECISION = 0;

public static final FieldType FIELD_TYPE = new FieldType();
Expand Down Expand Up @@ -104,6 +106,8 @@ public static class Builder extends AbstractFieldMapper.Builder<Builder, GeoMapp
private double precisionInMeters = -1;
private double distanceErrorPct = Defaults.DISTANCE_ERROR_PCT;

private ShapeBuilder.Orientation orientation = Defaults.ORIENTATION;

private SpatialPrefixTree prefixTree;

protected Builder(String name) {
Expand Down Expand Up @@ -148,6 +152,11 @@ public Builder distanceErrorPct(double distanceErrorPct) {
return this;
}

public Builder orientation(ShapeBuilder.Orientation orientation) {
this.orientation = orientation;
return this;
}

@Override
public GeoMapper build(BuilderContext context) {
final FieldMapper.Names names = buildNames(context);
Expand Down Expand Up @@ -177,7 +186,7 @@ public GeoMapper build(BuilderContext context) {
context.path().pathType(origPathType);


return new GeoMapper(names, tree, strategyName, distanceErrorPct, boostPrecision, wkbMapper, typeMapper, doubleMapper, bboxMapper, hashMapper, centroidMapper, fieldDataSettings, docValues, fieldType, postingsProvider,
return new GeoMapper(names, tree, strategyName, distanceErrorPct, orientation, boostPrecision, wkbMapper, typeMapper, doubleMapper, bboxMapper, hashMapper, centroidMapper, fieldDataSettings, docValues, fieldType, postingsProvider,
docValuesProvider, multiFieldsBuilder.build(this, context), copyTo);
}
}
Expand All @@ -204,6 +213,8 @@ public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext
builder.strategy(fieldNode.toString());
} else if (Names.BOOST_PRECISION.equals(fieldName)) {
builder.boostPrecision(Double.parseDouble(fieldNode.toString()));
} else if (Names.ORIENTATION.equals(fieldName)) {
builder.orientation(ShapeBuilder.orientationFromString(fieldNode.toString()));
}
}
return builder;
Expand Down Expand Up @@ -231,6 +242,7 @@ public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext
private final String defaultStrategyName;
private final double distanceErrorPct;
private final double boostPrecision;
private ShapeBuilder.Orientation shapeOrientation;

private static SpatialPrefixTree getSearchPrefixTree(String treeType) {
if (Names.TREE_GEOHASH.equals(treeType)) {
Expand All @@ -244,12 +256,12 @@ private static SpatialPrefixTree getSearchPrefixTree(String treeType) {
}

public GeoMapper(FieldMapper.Names names,
String tree, String defaultStrategyName, double distanceErrorPct, double boostPrecision, BinaryFieldMapper wkbMapper,
String tree, String defaultStrategyName, double distanceErrorPct, ShapeBuilder.Orientation shapeOrientation, double boostPrecision, BinaryFieldMapper wkbMapper,
StringFieldMapper typeMapper, DoubleFieldMapper areaMapper, GeoPointFieldMapper bboxMapper,
StringFieldMapper hashMapper, GeoPointFieldMapper centroidMapper, @Nullable Settings fieldDataSettings, Boolean docValues, FieldType fieldType,
PostingsFormatProvider postingsProvider, DocValuesFormatProvider docValuesProvider,
MultiFields multiFields, CopyTo copyTo) {
super(names, getSearchPrefixTree(tree), defaultStrategyName, distanceErrorPct, fieldType, postingsProvider, docValuesProvider, multiFields, copyTo);
super(names, getSearchPrefixTree(tree), defaultStrategyName, distanceErrorPct, shapeOrientation, fieldType, postingsProvider, docValuesProvider, multiFields, copyTo);
// super(names, 1, fieldType, docValues, null, null, postingsProvider, docValuesProvider, null, null, fieldDataSettings , null, multiFields, copyTo);
this.wkbMapper = wkbMapper;
this.typeMapper = typeMapper;
Expand All @@ -259,6 +271,7 @@ public GeoMapper(FieldMapper.Names names,
// this.wkbTextMapper = wkbTextMapper;
this.centroidMapper = centroidMapper;
this.defaultStrategyName = defaultStrategyName;
this.shapeOrientation = shapeOrientation;

// this.recursiveStrategy = new RecursivePrefixTreeStrategy(tree, names.indexName());
// this.recursiveStrategy.setDistErrPct(distanceErrorPct);
Expand Down

0 comments on commit 51f4456

Please sign in to comment.