Skip to content

Commit fb60e42

Browse files
committed
Remove IgnoreUnmapped on IGeoShape (#3214)
* Obsolete IgnoreUnmapped on IGeoShape This commit removes IgnoreUnmapped on IGeoShape. IgnoreUnmapped exists at the same level as _name and boost on a geo_shape query. (cherry picked from commit 1055eb2)
1 parent 96c0d4d commit fb60e42

17 files changed

+105
-167
lines changed

.paket/Paket.Restore.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848

4949
<!-- Because ReadAllText is slow on osx/linux, try to find shasum and awk -->
5050
<PropertyGroup>
51-
<PaketRestoreCachedHasher Condition="'$(OS)' != 'Windows_NT' And '$(PaketRestoreCachedHasher)' == '' And Exists('/usr/bin/shasum') And Exists('/usr/bin/awk')">/usr/bin/shasum $(PaketRestoreCacheFile) | /usr/bin/awk '{ print $1 }'</PaketRestoreCachedHasher>
52-
<PaketRestoreLockFileHasher Condition="'$(OS)' != 'Windows_NT' And '$(PaketRestoreLockFileHash)' == '' And Exists('/usr/bin/shasum') And Exists('/usr/bin/awk')">/usr/bin/shasum $(PaketLockFilePath) | /usr/bin/awk '{ print $1 }'</PaketRestoreLockFileHasher>
51+
<PaketRestoreCachedHasher Condition="'$(OS)' != 'Windows_NT' And '$(PaketRestoreCachedHasher)' == '' And Exists('/usr/bin/shasum') And Exists('/usr/bin/awk')">/usr/bin/shasum "$(PaketRestoreCacheFile)" | /usr/bin/awk '{ print $1 }'</PaketRestoreCachedHasher>
52+
<PaketRestoreLockFileHasher Condition="'$(OS)' != 'Windows_NT' And '$(PaketRestoreLockFileHash)' == '' And Exists('/usr/bin/shasum') And Exists('/usr/bin/awk')">/usr/bin/shasum "$(PaketLockFilePath)" | /usr/bin/awk '{ print $1 }'</PaketRestoreLockFileHasher>
5353
</PropertyGroup>
5454

5555
<!-- If shasum and awk exist get the hashes -->

src/Nest/QueryDsl/Geo/Shape/Circle/GeoShapeCircleQuery.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,22 @@ public class GeoShapeCircleQueryDescriptor<T>
2626
protected override bool Conditionless => GeoShapeCircleQuery.IsConditionless(this);
2727
ICircleGeoShape IGeoShapeCircleQuery.Shape { get; set; }
2828

29-
public GeoShapeCircleQueryDescriptor<T> Coordinates(GeoCoordinate coordinates, bool? ignoreUnmapped = null) => Assign(a =>
29+
public GeoShapeCircleQueryDescriptor<T> Coordinates(GeoCoordinate coordinates) => Assign(a =>
3030
{
3131
a.Shape = a.Shape ?? new CircleGeoShape();
3232
a.Shape.Coordinates = coordinates;
33-
a.Shape.IgnoreUnmapped = ignoreUnmapped;
3433
});
3534

36-
public GeoShapeCircleQueryDescriptor<T> Coordinates(double longitude, double latitude, bool? ignoreUnmapped = null) => Assign(a =>
35+
public GeoShapeCircleQueryDescriptor<T> Coordinates(double longitude, double latitude) => Assign(a =>
3736
{
3837
a.Shape = a.Shape ?? new CircleGeoShape();
3938
a.Shape.Coordinates = new GeoCoordinate(latitude, longitude);
40-
a.Shape.IgnoreUnmapped = ignoreUnmapped;
4139
});
4240

43-
public GeoShapeCircleQueryDescriptor<T> Radius(string radius, bool? ignoreUnmapped = null) => Assign(a =>
41+
public GeoShapeCircleQueryDescriptor<T> Radius(string radius) => Assign(a =>
4442
{
4543
a.Shape = a.Shape ?? new CircleGeoShape();
4644
a.Shape.Radius = radius;
47-
a.Shape.IgnoreUnmapped = ignoreUnmapped;
4845
});
4946
}
5047
}

src/Nest/QueryDsl/Geo/Shape/Envelope/GeoShapeEnvelopeQuery.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ public class GeoShapeEnvelopeQueryDescriptor<T>
2626
protected override bool Conditionless => GeoShapeEnvelopeQuery.IsConditionless(this);
2727
IEnvelopeGeoShape IGeoShapeEnvelopeQuery.Shape { get; set; }
2828

29-
public GeoShapeEnvelopeQueryDescriptor<T> Coordinates(IEnumerable<GeoCoordinate> coordinates, bool? ignoreUnmapped = null) => Assign(a =>
30-
{
31-
a.Shape = a.Shape ?? new EnvelopeGeoShape();
32-
a.Shape.Coordinates = coordinates;
33-
a.Shape.IgnoreUnmapped = ignoreUnmapped;
34-
});
29+
public GeoShapeEnvelopeQueryDescriptor<T> Coordinates(IEnumerable<GeoCoordinate> coordinates) =>
30+
Assign(a => a.Shape = new EnvelopeGeoShape { Coordinates = coordinates });
3531
}
3632
}

src/Nest/QueryDsl/Geo/Shape/GeoShapeBase.cs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,17 @@ public interface IGeoShape
1414
/// </summary>
1515
[JsonProperty("type")]
1616
string Type { get; }
17-
18-
/// <summary>
19-
/// Will ignore an unmapped field and will not match any documents for this query.
20-
/// This can be useful when querying multiple indexes which might have different mappings.
21-
/// </summary>
22-
[JsonProperty("ignore_unmapped")]
23-
bool? IgnoreUnmapped { get; set; }
2417
}
2518

19+
/// <summary>
20+
/// Base type for geo shapes
21+
/// </summary>
2622
public abstract class GeoShapeBase : IGeoShape
2723
{
2824
protected GeoShapeBase(string type) => this.Type = type;
2925

3026
/// <inheritdoc />
3127
public string Type { get; protected set; }
32-
33-
/// <inheritdoc />
34-
public bool? IgnoreUnmapped { get; set; }
3528
}
3629

3730
internal class GeoShapeConverter : JsonConverter
@@ -52,13 +45,11 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
5245

5346
internal static object ReadJToken(JToken shape, JsonSerializer serializer)
5447
{
55-
var type = shape["type"];
56-
var typeName = type?.Value<string>();
48+
var typeName = shape["type"]?.Value<string>();
5749
switch (typeName)
5850
{
5951
case "circle":
60-
var radius = shape["radius"];
61-
return ParseCircleGeoShape(shape, serializer, radius);
52+
return ParseCircleGeoShape(shape, serializer);
6253
case "envelope":
6354
return ParseEnvelopeGeoShape(shape, serializer);
6455
case "linestring":
@@ -80,8 +71,7 @@ internal static object ReadJToken(JToken shape, JsonSerializer serializer)
8071
}
8172
}
8273

83-
public override bool CanConvert(Type objectType) => typeof(IGeoShape).IsAssignableFrom(objectType) ||
84-
typeof(IGeometryCollection).IsAssignableFrom(objectType);
74+
public override bool CanConvert(Type objectType) => typeof(IGeoShape).IsAssignableFrom(objectType);
8575

8676
private static GeometryCollection ParseGeometryCollection(JToken shape, JsonSerializer serializer)
8777
{
@@ -126,11 +116,11 @@ private static LineStringGeoShape ParseLineStringGeoShape(JToken shape, JsonSeri
126116
private static EnvelopeGeoShape ParseEnvelopeGeoShape(JToken shape, JsonSerializer serializer) =>
127117
new EnvelopeGeoShape {Coordinates = GetCoordinates<IEnumerable<GeoCoordinate>>(shape, serializer)};
128118

129-
private static CircleGeoShape ParseCircleGeoShape(JToken shape, JsonSerializer serializer, JToken radius) =>
119+
private static CircleGeoShape ParseCircleGeoShape(JToken shape, JsonSerializer serializer) =>
130120
new CircleGeoShape
131121
{
132122
Coordinates = GetCoordinates<GeoCoordinate>(shape, serializer),
133-
Radius = radius?.Value<string>()
123+
Radius = shape["radius"]?.Value<string>()
134124
};
135125

136126
private static T GetCoordinates<T>(JToken shape, JsonSerializer serializer)

src/Nest/QueryDsl/Geo/Shape/GeoShapeQueryJsonConverter.cs

Lines changed: 27 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
namespace Nest
88
{
99
/// <summary>
10-
/// Marks an instance where _name and boost do not exist as children of the variable field but as siblings
10+
/// Marks an instance where _name, boost and ignore_unmapped do
11+
/// not exist as children of the variable field but as siblings
1112
/// </summary>
12-
internal class GeoShapeQueryFieldNameConverter : FieldNameQueryJsonConverter<GeoShapeCircleQuery>
13+
internal class GeoShapeQueryFieldNameConverter : ReserializeJsonConverter<GeoShapeCircleQuery, IGeoShapeQuery>
1314
{
14-
private static readonly string[] SkipProperties = {"boost", "_name"};
15+
private static readonly string[] SkipProperties = {"boost", "_name", "ignore_unmapped"};
1516
protected override bool SkipWriteProperty(string propertyName) => SkipProperties.Contains(propertyName);
1617

17-
protected override void SerializeJson(JsonWriter writer, object value, IFieldNameQuery castValue, JsonSerializer serializer)
18+
protected override void SerializeJson(JsonWriter writer, object value, IGeoShapeQuery castValue, JsonSerializer serializer)
1819
{
1920
var fieldName = castValue.Field;
2021
if (fieldName == null) return;
@@ -26,8 +27,10 @@ protected override void SerializeJson(JsonWriter writer, object value, IFieldNam
2627
writer.WriteStartObject();
2728
var name = castValue.Name;
2829
var boost = castValue.Boost;
30+
var ignoreUnmapped = castValue.IgnoreUnmapped;
2931
if (!name.IsNullOrEmpty()) writer.WriteProperty(serializer, "_name", name);
3032
if (boost != null) writer.WriteProperty(serializer, "boost", boost);
33+
if (ignoreUnmapped != null) writer.WriteProperty(serializer, "ignore_unmapped", ignoreUnmapped);
3134
writer.WritePropertyName(field);
3235
this.Reserialize(writer, value, serializer);
3336
writer.WriteEndObject();
@@ -47,15 +50,21 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
4750

4851
double? boost = null;
4952
string name = null;
50-
if (j.TryGetValue("boost", out var b) && (b.Type != JTokenType.Array && b.Type != JTokenType.Object))
53+
bool? ignoreUnmapped = null;
54+
if (j.TryGetValue("boost", out var boostToken) && (boostToken.Type != JTokenType.Array && boostToken.Type != JTokenType.Object))
5155
{
5256
j.Remove("boost");
53-
boost = b.Value<double?>();
57+
boost = boostToken.Value<double?>();
5458
}
55-
if (j.TryGetValue("_name", out var n) && n.Type == JTokenType.String)
59+
if (j.TryGetValue("_name", out var nameToken) && nameToken.Type == JTokenType.String)
5660
{
5761
j.Remove("_name");
58-
name = n.Value<string>();
62+
name = nameToken.Value<string>();
63+
}
64+
if (j.TryGetValue("ignore_unmapped", out var ignoreUnmappedToken) && ignoreUnmappedToken.Type == JTokenType.Boolean)
65+
{
66+
j.Remove("ignore_unmapped");
67+
ignoreUnmapped = ignoreUnmappedToken.Value<bool?>();
5968
}
6069
var firstProp = j.Properties().FirstOrDefault();
6170
if (firstProp == null) return null;
@@ -77,6 +86,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
7786
query.Name = name;
7887
query.Field = field;
7988
query.Relation = relation;
89+
query.IgnoreUnmapped = ignoreUnmapped;
8090
return query;
8191
}
8292

@@ -87,74 +97,33 @@ private static IGeoShapeQuery ParseShapeQuery(JToken shape, JsonSerializer seria
8797
{
8898
var type = shape["type"];
8999
var typeName = type?.Value<string>();
90-
var ignoreUnmapped = shape["ignore_unmapped"]?.Value<bool?>();
91-
92100
var geometry = GeoShapeConverter.ReadJToken(shape, serializer);
93-
94101
switch (typeName)
95102
{
96103
case "circle":
97-
return new GeoShapeCircleQuery
98-
{
99-
Shape = SetIgnoreUnmapped(geometry as ICircleGeoShape, ignoreUnmapped)
100-
};
104+
return new GeoShapeCircleQuery { Shape = geometry as ICircleGeoShape };
101105
case "envelope":
102-
return new GeoShapeEnvelopeQuery
103-
{
104-
Shape = SetIgnoreUnmapped(geometry as IEnvelopeGeoShape, ignoreUnmapped)
105-
};
106+
return new GeoShapeEnvelopeQuery { Shape = geometry as IEnvelopeGeoShape };
106107
case "linestring":
107-
return new GeoShapeLineStringQuery
108-
{
109-
Shape = SetIgnoreUnmapped(geometry as ILineStringGeoShape, ignoreUnmapped)
110-
};
108+
return new GeoShapeLineStringQuery { Shape = geometry as ILineStringGeoShape };
111109
case "multilinestring":
112-
return new GeoShapeMultiLineStringQuery
113-
{
114-
Shape = SetIgnoreUnmapped(geometry as IMultiLineStringGeoShape, ignoreUnmapped)
115-
};
110+
return new GeoShapeMultiLineStringQuery { Shape = geometry as IMultiLineStringGeoShape };
116111
case "point":
117-
return new GeoShapePointQuery
118-
{
119-
Shape = SetIgnoreUnmapped(geometry as IPointGeoShape, ignoreUnmapped)
120-
};
112+
return new GeoShapePointQuery { Shape = geometry as IPointGeoShape };
121113
case "multipoint":
122-
return new GeoShapeMultiPointQuery
123-
{
124-
Shape = SetIgnoreUnmapped(geometry as IMultiPointGeoShape, ignoreUnmapped)
125-
};
114+
return new GeoShapeMultiPointQuery { Shape = geometry as IMultiPointGeoShape };
126115
case "polygon":
127-
return new GeoShapePolygonQuery
128-
{
129-
Shape = SetIgnoreUnmapped(geometry as IPolygonGeoShape, ignoreUnmapped)
130-
};
116+
return new GeoShapePolygonQuery { Shape = geometry as IPolygonGeoShape };
131117
case "multipolygon":
132-
return new GeoShapeMultiPolygonQuery
133-
{
134-
Shape = SetIgnoreUnmapped(geometry as IMultiPolygonGeoShape, ignoreUnmapped)
135-
};
118+
return new GeoShapeMultiPolygonQuery { Shape = geometry as IMultiPolygonGeoShape };
136119
case "geometrycollection":
137-
var geometryCollection = geometry as IGeometryCollection;
138-
if (geometryCollection != null)
139-
{
140-
foreach (var innerGeometry in geometryCollection.Geometries)
141-
SetIgnoreUnmapped(innerGeometry, ignoreUnmapped);
142-
}
143-
144-
return new GeoShapeGeometryCollectionQuery { Shape = geometryCollection };
120+
return new GeoShapeGeometryCollectionQuery { Shape = geometry as IGeometryCollection };
145121
default:
146122
return null;
147123
}
148124
}
149125

150126
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) =>
151127
throw new NotSupportedException();
152-
153-
private static TShape SetIgnoreUnmapped<TShape>(TShape shape, bool? ignoreUnmapped) where TShape : IGeoShape
154-
{
155-
if (shape != null)
156-
shape.IgnoreUnmapped = ignoreUnmapped;
157-
return shape;
158-
}
159128
}
160129
}

src/Nest/QueryDsl/Geo/Shape/GeometryCollection/GeoShapeGeometryCollectionQuery.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,10 @@ public class GeoShapeGeometryCollectionQueryDescriptor<T>
2727

2828
IGeometryCollection IGeoShapeGeometryCollectionQuery.Shape { get; set; }
2929

30-
public GeoShapeGeometryCollectionQueryDescriptor<T> Geometries(IEnumerable<IGeoShape> geometries) => Assign(a =>
31-
{
32-
a.Shape = a.Shape ?? new GeometryCollection();
33-
a.Shape.Geometries = geometries;
34-
});
35-
36-
public GeoShapeGeometryCollectionQueryDescriptor<T> Geometries(params IGeoShape[] geometries) => Assign(a =>
37-
{
38-
a.Shape = a.Shape ?? new GeometryCollection();
39-
a.Shape.Geometries = geometries;
40-
});
30+
public GeoShapeGeometryCollectionQueryDescriptor<T> Geometries(IEnumerable<IGeoShape> geometries) =>
31+
Assign(a => a.Shape = new GeometryCollection { Geometries = geometries });
32+
33+
public GeoShapeGeometryCollectionQueryDescriptor<T> Geometries(params IGeoShape[] geometries) =>
34+
Assign(a => a.Shape = new GeometryCollection { Geometries = geometries });
4135
}
4236
}

src/Nest/QueryDsl/Geo/Shape/GeometryCollection/GeometryCollection.cs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,25 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using Newtonsoft.Json;
34

45
namespace Nest
56
{
67
/// <summary>
78
/// A geo shape representing a collection of <see cref="IGeoShape"/> geometries
89
/// </summary>
9-
[ContractJsonConverter(typeof(GeoShapeConverter))]
10-
public interface IGeometryCollection
10+
public interface IGeometryCollection : IGeoShape
1111
{
12-
/// <summary>
13-
/// The type of geo shape
14-
/// </summary>
15-
[JsonProperty("type")]
16-
string Type { get; }
17-
1812
/// <summary>
1913
/// A collection of <see cref="IGeoShape"/> geometries
2014
/// </summary>
2115
[JsonProperty("geometries")]
2216
IEnumerable<IGeoShape> Geometries { get; set; }
2317
}
2418

25-
// TODO: IGeometryCollection should implement IGeoShape
2619
/// <inheritdoc cref="IGeometryCollection"/>
27-
public class GeometryCollection : IGeometryCollection, IGeoShape
20+
public class GeometryCollection : GeoShapeBase, IGeometryCollection
2821
{
29-
/// <inheritdoc />
30-
public string Type => "geometrycollection";
31-
32-
/// <inheritdoc />
33-
string IGeoShape.Type => this.Type;
34-
35-
/// <inheritdoc />
36-
public bool? IgnoreUnmapped { get; set; }
22+
public GeometryCollection() : base("geometrycollection") { }
3723

3824
/// <inheritdoc />
3925
public IEnumerable<IGeoShape> Geometries { get; set; }

src/Nest/QueryDsl/Geo/Shape/IGeoShapeQuery.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,21 @@ public interface IGeoShapeQuery : IFieldNameQuery
1212
[JsonProperty("relation")]
1313
GeoShapeRelation? Relation { get; set; }
1414

15+
/// <summary>
16+
/// Will ignore an unmapped field and will not match any documents for this query.
17+
/// This can be useful when querying multiple indexes which might have different mappings.
18+
/// </summary>
19+
[JsonProperty("ignore_unmapped")]
20+
bool? IgnoreUnmapped { get; set; }
1521
}
1622

1723
public abstract class GeoShapeQueryBase : FieldNameQueryBase, IGeoShapeQuery
1824
{
19-
/// <summary>
20-
/// Controls the spatial relation operator to use at search time.
21-
/// </summary>
25+
/// <inheritdoc />
2226
public GeoShapeRelation? Relation { get; set; }
2327

28+
/// <inheritdoc />
29+
public bool? IgnoreUnmapped { get; set; }
2430
}
2531

2632
public abstract class GeoShapeQueryDescriptorBase<TDescriptor, TInterface, T>
@@ -30,16 +36,12 @@ public abstract class GeoShapeQueryDescriptorBase<TDescriptor, TInterface, T>
3036
where T : class
3137
{
3238
GeoShapeRelation? IGeoShapeQuery.Relation { get; set; }
39+
bool? IGeoShapeQuery.IgnoreUnmapped { get; set; }
3340

34-
/// <summary>
35-
/// Controls the spatial relation operator to used at search time.
36-
/// </summary>
41+
/// <inheritdoc cref="IGeoShapeQuery.Relation"/>
3742
public TDescriptor Relation(GeoShapeRelation? relation) => Assign(a => a.Relation = relation);
3843

39-
// /// <summary>
40-
// /// Will ignore an unmapped field and will not match any documents for this query.
41-
// /// This can be useful when querying multiple indexes which might have different mappings.
42-
// /// </summary>
43-
// public TDescriptor IgnoreUnmapped(bool? ignoreUnmapped = true) => Assign(a => a.IgnoreUnmapped = ignoreUnmapped);
44+
/// <inheritdoc cref="IGeoShapeQuery.IgnoreUnmapped"/>
45+
public TDescriptor IgnoreUnmapped(bool? ignoreUnmapped = true) => Assign(a => a.IgnoreUnmapped = ignoreUnmapped);
4446
}
4547
}

src/Nest/QueryDsl/Geo/Shape/LineString/GeoShapeLineStringQuery.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ public class GeoShapeLineStringQueryDescriptor<T>
2626
protected override bool Conditionless => GeoShapeLineStringQuery.IsConditionless(this);
2727
ILineStringGeoShape IGeoShapeLineStringQuery.Shape { get; set; }
2828

29-
public GeoShapeLineStringQueryDescriptor<T> Coordinates(IEnumerable<GeoCoordinate> coordinates, bool? ignoreUnmapped = null) => Assign(a =>
30-
{
31-
a.Shape = a.Shape ?? new LineStringGeoShape();
32-
a.Shape.Coordinates = coordinates;
33-
a.Shape.IgnoreUnmapped = ignoreUnmapped;
34-
});
29+
public GeoShapeLineStringQueryDescriptor<T> Coordinates(IEnumerable<GeoCoordinate> coordinates) =>
30+
Assign(a => a.Shape = new LineStringGeoShape { Coordinates = coordinates });
3531
}
3632
}

0 commit comments

Comments
 (0)