Skip to content

Commit 203af45

Browse files
committed
Merge branch 'fix/1713'
2 parents a7090a8 + 7d50e9c commit 203af45

File tree

14 files changed

+293
-250
lines changed

14 files changed

+293
-250
lines changed

paket.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ NUGET
304304
xunit (2.1.0)
305305
xunit.assert (2.1.0)
306306
xunit.core (2.1.0)
307-
xunit.abstractions (2.0.0) - framework: >= net45, dnx451, dnxcore50, monoandroid, monotouch, portable-net45+win80+wp80+wpa81, xamarinios, winv4.5, wpv8.0
307+
xunit.abstractions (2.0.0) - framework: >= net45, dnx451, dnxcore50, monoandroid, monotouch, portable-net45+win80+wp80+wpa81, xamarinios, winv4.5, wpv8.1, wpv8.0
308308
xunit.assert (2.1.0)
309309
System.Collections (>= 4.0.0) - framework: dnxcore50
310310
System.Diagnostics.Debug (>= 4.0.0) - framework: dnxcore50
@@ -328,11 +328,11 @@ NUGET
328328
System.Runtime.Extensions (>= 4.0.0) - framework: dnxcore50
329329
System.Threading.Tasks (>= 4.0.0) - framework: dnxcore50
330330
xunit.abstractions (>= 2.0.0) - framework: dnxcore50
331-
xunit.extensibility.core (2.1.0) - framework: >= net45, dnx451, dnxcore50, monoandroid, monotouch, portable-net45+win80+wp80+wpa81, xamarinios, winv4.5, wpv8.0
332-
xunit.extensibility.execution (2.1.0) - framework: >= net45, dnx451, dnxcore50, monoandroid, monotouch, portable-net45+win80+wp80+wpa81, xamarinios, winv4.5, wpv8.0
333-
xunit.extensibility.core (2.1.0) - framework: >= net45, dnx451, dnxcore50, monoandroid, monotouch, portable-net45+win80+wp80+wpa81, xamarinios, winv4.5, wpv8.0
331+
xunit.extensibility.core (2.1.0) - framework: >= net45, dnx451, dnxcore50, monoandroid, monotouch, portable-net45+win80+wp80+wpa81, xamarinios, winv4.5, wpv8.1, wpv8.0
332+
xunit.extensibility.execution (2.1.0) - framework: >= net45, dnx451, dnxcore50, monoandroid, monotouch, portable-net45+win80+wp80+wpa81, xamarinios, winv4.5, wpv8.1, wpv8.0
333+
xunit.extensibility.core (2.1.0) - framework: >= net45, dnx451, dnxcore50, monoandroid, monotouch, portable-net45+win80+wp80+wpa81, xamarinios, winv4.5, wpv8.1, wpv8.0
334334
xunit.abstractions (2.0.0)
335-
xunit.extensibility.execution (2.1.0) - framework: >= net45, dnx451, dnxcore50, monoandroid, monotouch, portable-net45+win80+wp80+wpa81, xamarinios, winv4.5, wpv8.0
335+
xunit.extensibility.execution (2.1.0) - framework: >= net45, dnx451, dnxcore50, monoandroid, monotouch, portable-net45+win80+wp80+wpa81, xamarinios, winv4.5, wpv8.1, wpv8.0
336336
System.Collections (>= 4.0.0) - framework: dnxcore50
337337
System.Diagnostics.Debug (>= 4.0.0) - framework: dnxcore50
338338
System.Globalization (>= 4.0.0) - framework: dnxcore50
@@ -347,7 +347,7 @@ NUGET
347347
System.Threading (>= 4.0.0) - framework: dnxcore50
348348
System.Threading.Tasks (>= 4.0.0) - framework: dnxcore50
349349
xunit.abstractions (>= 2.0.0) - framework: dnxcore50
350-
xunit.extensibility.core (2.1.0) - framework: >= net45, dnx451, dnxcore50, monoandroid, monotouch, xamarinios, winv4.5, wpv8.0
350+
xunit.extensibility.core (2.1.0) - framework: >= net45, dnx451, dnxcore50, monoandroid, monotouch, xamarinios, winv4.5, wpv8.1, wpv8.0
351351

352352
GROUP build
353353
NUGET

src/CodeGeneration/CodeGeneration.LowLevelClient/Domain/ApiQueryParameters.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,16 @@ public string CsharpType(string paramName)
3737
}
3838
}
3939

40+
public string HighLevelType(string paramName)
41+
{
42+
var csharpType = this.CsharpType(paramName);
43+
switch (csharpType)
44+
{
45+
case "TimeSpan":
46+
return "Time";
47+
default:
48+
return csharpType;
49+
}
50+
}
4051
}
4152
}

src/CodeGeneration/CodeGeneration.LowLevelClient/Views/_Descriptors.Generated.cshtml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ namespace Nest
4242
}
4343
</text>foreach (KeyValuePair<string, ApiQueryParameters> kv in method.Url.Params)
4444
{
45-
if (method.Url.Parts != null && method.Url.Parts.ContainsKey(kv.Key))
46-
{
47-
continue;
48-
}
49-
var t = @kv.Value.CsharpType(kv.Key);
45+
if (method.Url.Parts != null && method.Url.Parts.ContainsKey(kv.Key))
46+
{
47+
continue;
48+
}
49+
var t = @kv.Value.HighLevelType(kv.Key);
50+
var tMethod = t == "Time" ? ".ToTimeSpan()" : "";
5051
var tSuffix = (t == "bool") ? " = true" : "";
5152
var m = kv.Key.ToPascalCase();
5253
var mm = (m != "Type" && m != "Index" && m != "Script") ? m : m + "QueryString";
@@ -60,7 +61,7 @@ namespace Nest
6061
{<text>
6162
[Obsolete("Scheduled to be removed in 2.0, use @kv.Value.DeprecatedInFavorOf instead")]
6263
</text>}
63-
public @Raw(type) @(mm)(@t @kv.Key@tSuffix) => AssignParam(p=>p.@(m)(@kv.Key));</text>
64+
public @Raw(type) @(mm)(@t @kv.Key@tSuffix) => AssignParam(p=>p.@(m)(@kv.Key@tMethod));</text>
6465
if (fieldMethod)
6566
{
6667
<text>

src/CodeGeneration/CodeGeneration.LowLevelClient/Views/_Requests.Generated.cshtml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace Nest
6666
var original = kv.Value.OriginalQueryStringParamName;
6767
var cased = kv.Key.ToPascalCase();
6868
var mm = (cased != "Type" && cased != "Index" && cased != "Script") ? cased : cased + "QueryString";
69-
var fieldType = kv.Value.CsharpType(kv.Key).Replace("params", "");
69+
var fieldType = kv.Value.HighLevelType(kv.Key).Replace("params", "");
7070
var isFields = (original.Contains("fields") || original.Contains("source_include") || original.Contains("source_exclude"));
7171
if (isFields && fieldType.Contains("string"))
7272
{
@@ -76,12 +76,17 @@ namespace Nest
7676
{
7777
fieldType = "Field";
7878
}
79+
var setter = "value";
80+
if (fieldType == "Time")
81+
{
82+
setter += ".ToString()";
83+
}
7984
<text>///<summary>@kv.Value.Description</summary>
8085
@if(!string.IsNullOrWhiteSpace(kv.Value.DeprecatedInFavorOf))
8186
{
8287
<text>[Obsolete("Scheduled to be removed in 2.0, use @kv.Value.DeprecatedInFavorOf instead")]</text>
8388
}
84-
public @Raw(fieldType) @(mm) { get { return Q@(Raw("<" + fieldType + ">"))("@original"); } set { Q("@original", value); } }
89+
public @Raw(fieldType) @(mm) { get { return Q@(Raw("<" + fieldType + ">"))("@original"); } set { Q("@original", @setter); } }
8590
</text>
8691
}
8792
@if (method.RequestTypeUnmapped)

src/Nest/CommonAbstractions/Request/RequestBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ protected RequestBase(Func<RouteValues, RouteValues> pathSelector)
5151
protected TOut Q<TOut>(string name) => RequestState.RequestParameters.GetQueryStringValue<TOut>(name);
5252

5353
protected void Q(string name, object value) => RequestState.RequestParameters.AddQueryStringValue(name, value);
54-
5554
}
5655

5756
public abstract class RequestDescriptorBase<TDescriptor, TParameters, TInterface> : RequestBase<TParameters>, IDescriptor

src/Nest/CommonOptions/TimeUnit/Time.cs

Lines changed: 61 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ public class Time : IComparable<Time>, IEquatable<Time>
1010
{
1111
private static readonly Regex _expressionRegex = new Regex(@"^(?<factor>\d+(?:\.\d+)?)(?<interval>(?:y|M|w|d|h|m|s|ms))?$", RegexOptions.Compiled | RegexOptions.ExplicitCapture);
1212

13-
private static readonly long _year = (long)TimeSpan.FromDays(365).TotalMilliseconds;
14-
private static readonly long _week = (long)TimeSpan.FromDays(7).TotalMilliseconds;
15-
private static readonly long _day = (long)TimeSpan.FromDays(1).TotalMilliseconds;
16-
private static readonly long _hour = (long)TimeSpan.FromHours(1).TotalMilliseconds;
17-
private static readonly long _minute = (long)TimeSpan.FromMinutes(1).TotalMilliseconds;
18-
private static readonly long _second = (long)TimeSpan.FromSeconds(1).TotalMilliseconds;
13+
private static readonly double _year = TimeSpan.FromDays(365).TotalMilliseconds;
14+
private static readonly double _week = TimeSpan.FromDays(7).TotalMilliseconds;
15+
private static readonly double _day = TimeSpan.FromDays(1).TotalMilliseconds;
16+
private static readonly double _hour = TimeSpan.FromHours(1).TotalMilliseconds;
17+
private static readonly double _minute = TimeSpan.FromMinutes(1).TotalMilliseconds;
18+
private static readonly double _second = TimeSpan.FromSeconds(1).TotalMilliseconds;
1919

20-
public double? Factor { get; }
21-
public TimeUnit? Interval { get; }
22-
public long Milliseconds { get; }
20+
public double? Factor { get; private set; }
21+
public TimeUnit? Interval { get; private set; }
22+
public double Milliseconds { get; private set; }
2323

2424
public static implicit operator Time(TimeSpan span) => new Time(span);
25-
public static implicit operator Time(long milliseconds) => new Time(milliseconds);
25+
public static implicit operator Time(double milliseconds) => new Time(milliseconds);
2626
public static implicit operator Time(string expression) => new Time(expression);
2727

2828
public Time(double factor, TimeUnit interval)
@@ -48,49 +48,12 @@ public Time(double factor, TimeUnit interval)
4848

4949
public Time(TimeSpan timeSpan)
5050
{
51-
var ms = timeSpan.TotalMilliseconds;
52-
this.Milliseconds = (long)ms;
53-
54-
if (ms >= _year)
55-
{
56-
Factor = ms / _year;
57-
Interval = TimeUnit.Year;
58-
}
59-
else if (ms >= _week)
60-
{
61-
Factor = ms / _week;
62-
Interval = TimeUnit.Week;
63-
}
64-
else if (ms >= _day)
65-
{
66-
Factor = ms / _day;
67-
Interval = TimeUnit.Day;
68-
}
69-
else if (ms >= _hour)
70-
{
71-
Factor = ms / _hour;
72-
Interval = TimeUnit.Hour;
73-
}
74-
else if (ms >= _minute)
75-
{
76-
Factor = ms / _minute;
77-
Interval = TimeUnit.Minute;
78-
}
79-
else if (ms >= _second)
80-
{
81-
Factor = ms / _second;
82-
Interval = TimeUnit.Second;
83-
}
84-
else
85-
{
86-
Factor = ms;
87-
Interval = TimeUnit.Millisecond;
88-
}
51+
Reduce(timeSpan.TotalMilliseconds);
8952
}
9053

91-
public Time(long milliseconds)
54+
public Time(double milliseconds)
9255
{
93-
this.Milliseconds = milliseconds;
56+
Reduce(milliseconds);
9457
}
9558

9659
public Time(string timeUnit)
@@ -120,8 +83,6 @@ public Time(string timeUnit)
12083
Milliseconds = (long)this.Factor;
12184
}
12285

123-
public TimeSpan ToTimeSpan() => TimeSpan.FromMilliseconds(this.Milliseconds);
124-
12586
public int CompareTo(Time other)
12687
{
12788
if (other == null) return 1;
@@ -136,17 +97,18 @@ public int CompareTo(Time other)
13697
public static bool operator >(Time left, Time right) => left.CompareTo(right) > 0;
13798
public static bool operator >=(Time left, Time right) => left.CompareTo(right) > 0 || left.Equals(right);
13899

139-
public static bool operator ==(Time left, Time right) =>
100+
public static bool operator ==(Time left, Time right) =>
140101
object.ReferenceEquals(left, null) ? object.ReferenceEquals(right, null) : left.Equals(right);
141102

142103
public static bool operator !=(Time left, Time right) =>
143104
!object.ReferenceEquals(left, null) && !object.ReferenceEquals(right, null) && !left.Equals(right);
144105

106+
public TimeSpan ToTimeSpan() => TimeSpan.FromMilliseconds(this.Milliseconds);
107+
145108
public override string ToString()
146109
{
147-
if (this.Factor == null) return this.Milliseconds.ToString(CultureInfo.InvariantCulture);
148-
return this.Factor.Value.ToString("0.##", CultureInfo.InvariantCulture) +
149-
this.Interval.GetValueOrDefault().GetStringValue();
110+
var factor = this.Factor.Value.ToString("0.##", CultureInfo.InvariantCulture);
111+
return (this.Interval.HasValue) ? factor + this.Interval.Value.GetStringValue() : factor;
150112
}
151113

152114
public bool Equals(Time other)
@@ -166,5 +128,48 @@ public override bool Equals(object obj)
166128

167129
public override int GetHashCode() => this.Milliseconds.GetHashCode();
168130

131+
private void Reduce(double ms)
132+
{
133+
this.Milliseconds = ms;
134+
135+
if (ms >= _year)
136+
{
137+
Factor = ms / _year;
138+
Interval = TimeUnit.Year;
139+
}
140+
else if (ms >= _week)
141+
{
142+
Factor = ms / _week;
143+
Interval = TimeUnit.Week;
144+
}
145+
else if (ms >= _day)
146+
{
147+
Factor = ms / _day;
148+
Interval = TimeUnit.Day;
149+
}
150+
else if (ms >= _hour)
151+
{
152+
Factor = ms / _hour;
153+
Interval = TimeUnit.Hour;
154+
}
155+
else if (ms >= _minute)
156+
{
157+
Factor = ms / _minute;
158+
Interval = TimeUnit.Minute;
159+
}
160+
else if (ms >= _second)
161+
{
162+
Factor = ms / _second;
163+
Interval = TimeUnit.Second;
164+
}
165+
else
166+
{
167+
Factor = ms;
168+
// If milliseconds is < 0 then don't set an interval.
169+
// This is used when setting things like index.refresh_interval = -1 (the only case where a unit isn't required)
170+
if (ms > 0)
171+
Interval = TimeUnit.Millisecond;
172+
}
173+
}
169174
}
170175
}

src/Nest/CommonOptions/TimeUnit/TimeJsonConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ internal class TimeJsonConverter : JsonConverter
88
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
99
{
1010
var v = value as Time;
11-
if (v.Factor.HasValue)
11+
if (v.Factor.HasValue && v.Interval.HasValue)
1212
writer.WriteValue(v.ToString());
13-
else writer.WriteValue(v.Milliseconds);
13+
else writer.WriteValue((long)v.Milliseconds);
1414
}
1515

1616
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)

src/Nest/Document/Multiple/Reindex/ReindexObservable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private void Reindex(IObserver<IReindexResponse<T>> observer)
6060
.Size(size)
6161
.Query(q=>this._reindexRequest.Query)
6262
.SearchType(SearchType.Scan)
63-
.Scroll(scroll.ToTimeSpan())
63+
.Scroll(scroll)
6464
);
6565
if (searchResult.Total <= 0)
6666
throw new ElasticsearchClientException(PipelineFailure.BadResponse, $"Source index {fromIndex} doesn't contain any documents.", searchResult.ApiCall);

0 commit comments

Comments
 (0)