public RangeQueryBuilder relation(String relation) { if (relation == null) { throw new IllegalArgumentException("relation cannot be null"); } this.relation = ShapeRelation.getRelationByName(relation); if (this.relation == null) { throw new IllegalArgumentException(relation + " is not a valid relation"); } if (!isRelationAllowed(this.relation)) { throw new IllegalArgumentException("[range] query does not support relation [" + relation + "]"); } return this; }
/** * Defines which spatial strategy will be used for building the geo shape * Query. When not set, the strategy that will be used will be the one that * is associated with the geo shape field in the mappings. * * @param strategy * The spatial strategy to use for building the geo shape Query * @return this */ public GeoShapeQueryBuilder strategy(SpatialStrategy strategy) { if (strategy != null && strategy == SpatialStrategy.TERM && relation != ShapeRelation.INTERSECTS) { throw new IllegalArgumentException("strategy [" + strategy.getStrategyName() + "] only supports relation [" + ShapeRelation.INTERSECTS.getRelationName() + "] found relation [" + relation.getRelationName() + "]"); } this.strategy = strategy; return this; }
public static ShapeRelation getRelationByName(String name) { name = name.toLowerCase(Locale.ENGLISH); for (ShapeRelation relation : ShapeRelation.values()) { if (relation.relationName.equals(name)) { return relation; } } return null; }
@Override protected void doWriteTo(StreamOutput out) throws IOException { if (supplier != null) { throw new IllegalStateException("supplier must be null, can't serialize suppliers, missing a rewriteAndFetch?"); } out.writeString(fieldName); boolean hasShape = shape != null; out.writeBoolean(hasShape); if (hasShape) { out.writeNamedWriteable(shape); } else { out.writeOptionalString(indexedShapeId); out.writeOptionalString(indexedShapeType); out.writeOptionalString(indexedShapeIndex); out.writeOptionalString(indexedShapePath); if (out.getVersion().onOrAfter(Version.V_6_4_0)) { out.writeOptionalString(indexedShapeRouting); } else if (indexedShapeRouting != null) { throw new IllegalStateException("indexed shape routing cannot be serialized to older nodes"); } } relation.writeTo(out); out.writeOptionalWriteable(strategy); out.writeBoolean(ignoreUnmapped); }
/** * Read from a stream. */ public GeoShapeQueryBuilder(StreamInput in) throws IOException { super(in); fieldName = in.readString(); if (in.readBoolean()) { shape = in.readNamedWriteable(ShapeBuilder.class); indexedShapeId = null; indexedShapeType = null; } else { shape = null; indexedShapeId = in.readOptionalString(); indexedShapeType = in.readOptionalString(); indexedShapeIndex = in.readOptionalString(); indexedShapePath = in.readOptionalString(); if (in.getVersion().onOrAfter(Version.V_6_4_0)) { indexedShapeRouting = in.readOptionalString(); } else { indexedShapeRouting = null; } } relation = ShapeRelation.readFromStream(in); strategy = in.readOptionalWriteable(SpatialStrategy::readFromStream); ignoreUnmapped = in.readBoolean(); supplier = null; }
private Query getVectorQueryFromShape(QueryShardContext context, Object queryShape) { Query geoQuery; if (queryShape instanceof Line[]) { geoQuery = XLatLonShape.newLineQuery(fieldName(), relation.getLuceneRelation(), (Line[]) queryShape); } else if (queryShape instanceof Polygon[]) { geoQuery = XLatLonShape.newPolygonQuery(fieldName(), relation.getLuceneRelation(), (Polygon[]) queryShape); } else if (queryShape instanceof Line) { geoQuery = XLatLonShape.newLineQuery(fieldName(), relation.getLuceneRelation(), (Line) queryShape); } else if (queryShape instanceof Polygon) { geoQuery = XLatLonShape.newPolygonQuery(fieldName(), relation.getLuceneRelation(), (Polygon) queryShape); } else if (queryShape instanceof Rectangle) { Rectangle r = (Rectangle) queryShape; geoQuery = XLatLonShape.newBoxQuery(fieldName(), relation.getLuceneRelation(), r.minLat, r.maxLat, r.minLon, r.maxLon); } else if (queryShape instanceof double[][]) { return XLatLonShape.newBoxQuery(fieldName, relation.getLuceneRelation(), pt[1], pt[1], pt[0], pt[0]); } else if (queryShape instanceof Object[]) { geoQuery = createGeometryCollectionQuery(context, (Object[]) queryShape);
@Override protected void doWriteTo(StreamOutput out) throws IOException { if (supplier != null) { throw new IllegalStateException("supplier must be null, can't serialize suppliers, missing a rewriteAndFetch?"); } out.writeString(fieldName); boolean hasShape = shape != null; out.writeBoolean(hasShape); if (hasShape) { out.writeNamedWriteable(shape); } else { out.writeOptionalString(indexedShapeId); out.writeOptionalString(indexedShapeType); out.writeOptionalString(indexedShapeIndex); out.writeOptionalString(indexedShapePath); if (out.getVersion().onOrAfter(Version.V_6_4_0)) { out.writeOptionalString(indexedShapeRouting); } else if (indexedShapeRouting != null) { throw new IllegalStateException("indexed shape routing cannot be serialized to older nodes"); } } relation.writeTo(out); out.writeOptionalWriteable(strategy); out.writeBoolean(ignoreUnmapped); }
/** * Read from a stream. */ public GeoShapeQueryBuilder(StreamInput in) throws IOException { super(in); fieldName = in.readString(); if (in.readBoolean()) { shape = in.readNamedWriteable(ShapeBuilder.class); indexedShapeId = null; indexedShapeType = null; } else { shape = null; indexedShapeId = in.readOptionalString(); indexedShapeType = in.readOptionalString(); indexedShapeIndex = in.readOptionalString(); indexedShapePath = in.readOptionalString(); } relation = ShapeRelation.readFromStream(in); strategy = in.readOptionalWriteable(SpatialStrategy::readFromStream); ignoreUnmapped = in.readBoolean(); }
/** * Read from a stream. */ public RangeQueryBuilder(StreamInput in) throws IOException { super(in); fieldName = in.readString(); from = in.readGenericValue(); to = in.readGenericValue(); includeLower = in.readBoolean(); includeUpper = in.readBoolean(); timeZone = in.readOptionalTimeZone(); String formatString = in.readOptionalString(); if (formatString != null) { format = DateFormatter.forPattern(formatString); } if (in.getVersion().onOrAfter(Version.V_5_2_0)) { String relationString = in.readOptionalString(); if (relationString != null) { relation = ShapeRelation.getRelationByName(relationString); if (relation != null && !isRelationAllowed(relation)) { throw new IllegalArgumentException( "[range] query does not support relation [" + relationString + "]"); } } } }
/** * Sets the relation of query shape and indexed shape. * * @param relation relation of the shapes * @return this */ public GeoShapeQueryBuilder relation(ShapeRelation relation) { if (relation == null) { throw new IllegalArgumentException("No Shape Relation defined"); } if (SpatialStrategy.TERM.equals(strategy) && relation != ShapeRelation.INTERSECTS) { throw new IllegalArgumentException("current strategy [" + strategy.getStrategyName() + "] only supports relation [" + ShapeRelation.INTERSECTS.getRelationName() + "] found relation [" + relation.getRelationName() + "]"); } this.relation = relation; return this; }
public static ShapeRelation getRelationByName(String name) { name = name.toLowerCase(Locale.ENGLISH); for (ShapeRelation relation : ShapeRelation.values()) { if (relation.relationName.equals(name)) { return relation; } } return null; }
@Override protected void doWriteTo(StreamOutput out) throws IOException { if (supplier != null) { throw new IllegalStateException("supplier must be null, can't serialize suppliers, missing a rewriteAndFetch?"); } out.writeString(fieldName); boolean hasShape = shape != null; out.writeBoolean(hasShape); if (hasShape) { out.writeNamedWriteable(shape); } else { out.writeOptionalString(indexedShapeId); out.writeOptionalString(indexedShapeType); out.writeOptionalString(indexedShapeIndex); out.writeOptionalString(indexedShapePath); if (out.getVersion().onOrAfter(Version.V_6_4_0)) { out.writeOptionalString(indexedShapeRouting); } else if (indexedShapeRouting != null) { throw new IllegalStateException("indexed shape routing cannot be serialized to older nodes"); } } relation.writeTo(out); out.writeOptionalWriteable(strategy); out.writeBoolean(ignoreUnmapped); }
/** * Read from a stream. */ public GeoShapeQueryBuilder(StreamInput in) throws IOException { super(in); fieldName = in.readString(); if (in.readBoolean()) { shape = in.readNamedWriteable(ShapeBuilder.class); indexedShapeId = null; indexedShapeType = null; } else { shape = null; indexedShapeId = in.readOptionalString(); indexedShapeType = in.readOptionalString(); indexedShapeIndex = in.readOptionalString(); indexedShapePath = in.readOptionalString(); if (in.getVersion().onOrAfter(Version.V_6_4_0)) { indexedShapeRouting = in.readOptionalString(); } else { indexedShapeRouting = null; } } relation = ShapeRelation.readFromStream(in); strategy = in.readOptionalWriteable(SpatialStrategy::readFromStream); ignoreUnmapped = in.readBoolean(); supplier = null; }
public RangeQueryBuilder relation(String relation) { if (relation == null) { throw new IllegalArgumentException("relation cannot be null"); } this.relation = ShapeRelation.getRelationByName(relation); if (this.relation == null) { throw new IllegalArgumentException(relation + " is not a valid relation"); } return this; }
@Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(NAME); builder.startObject(fieldName); builder.field(FROM_FIELD.getPreferredName(), maybeConvertToString(this.from)); builder.field(TO_FIELD.getPreferredName(), maybeConvertToString(this.to)); builder.field(INCLUDE_LOWER_FIELD.getPreferredName(), includeLower); builder.field(INCLUDE_UPPER_FIELD.getPreferredName(), includeUpper); if (timeZone != null) { builder.field(TIME_ZONE_FIELD.getPreferredName(), timeZone.getID()); } if (format != null) { builder.field(FORMAT_FIELD.getPreferredName(), format.pattern()); } if (relation != null) { builder.field(RELATION_FIELD.getPreferredName(), relation.getRelationName()); } printBoostAndQueryName(builder); builder.endObject(); builder.endObject(); }
public static ShapeRelation getRelationByName(String name) { name = name.toLowerCase(Locale.ENGLISH); for (ShapeRelation relation : ShapeRelation.values()) { if (relation.relationName.equals(name)) { return relation; } } return null; }
@Override protected void doWriteTo(StreamOutput out) throws IOException { out.writeString(fieldName); boolean hasShape = shape != null; out.writeBoolean(hasShape); if (hasShape) { out.writeNamedWriteable(shape); } else { out.writeOptionalString(indexedShapeId); out.writeOptionalString(indexedShapeType); out.writeOptionalString(indexedShapeIndex); out.writeOptionalString(indexedShapePath); } relation.writeTo(out); out.writeOptionalWriteable(strategy); out.writeBoolean(ignoreUnmapped); }
/** * Read from a stream. */ public GeoShapeQueryBuilder(StreamInput in) throws IOException { super(in); fieldName = in.readString(); if (in.readBoolean()) { shape = in.readNamedWriteable(ShapeBuilder.class); indexedShapeId = null; indexedShapeType = null; } else { shape = null; indexedShapeId = in.readOptionalString(); indexedShapeType = in.readOptionalString(); indexedShapeIndex = in.readOptionalString(); indexedShapePath = in.readOptionalString(); if (in.getVersion().onOrAfter(Version.V_6_4_0)) { indexedShapeRouting = in.readOptionalString(); } else { indexedShapeRouting = null; } } relation = ShapeRelation.readFromStream(in); strategy = in.readOptionalWriteable(SpatialStrategy::readFromStream); ignoreUnmapped = in.readBoolean(); supplier = null; }
public RangeQueryBuilder relation(String relation) { if (relation == null) { throw new IllegalArgumentException("relation cannot be null"); } this.relation = ShapeRelation.getRelationByName(relation); if (this.relation == null) { throw new IllegalArgumentException(relation + " is not a valid relation"); } if (!isRelationAllowed(this.relation)) { throw new IllegalArgumentException("[range] query does not support relation [" + relation + "]"); } return this; }
builder.field(RELATION_FIELD.getPreferredName(), relation.getRelationName());