Skip to content

Commit c72f3f3

Browse files
committed
High level methods now take Time instead of TimeSpan
Closes #1713
1 parent 8454c4a commit c72f3f3

File tree

10 files changed

+1000
-976
lines changed

10 files changed

+1000
-976
lines changed

Diff for: src/CodeGeneration/CodeGeneration.LowLevelClient/Domain/ApiQueryParameters.cs

+11
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
}

Diff for: src/CodeGeneration/CodeGeneration.LowLevelClient/Views/_Descriptors.Generated.cshtml

+7-6
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>

Diff for: src/CodeGeneration/CodeGeneration.LowLevelClient/Views/_Requests.Generated.cshtml

+7-2
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 += ".ToTimeSpan()";
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@(Raw("<" + fieldType + ">"))("@original", @setter); } }
8590
</text>
8691
}
8792
@if (method.RequestTypeUnmapped)

Diff for: src/Nest/CommonAbstractions/Request/RequestBase.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ protected RequestBase(Func<RouteValues, RouteValues> pathSelector)
5050

5151
protected TOut Q<TOut>(string name) => RequestState.RequestParameters.GetQueryStringValue<TOut>(name);
5252

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

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

Diff for: src/Nest/CommonOptions/TimeUnit/Time.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ public Time(string timeUnit)
120120
Milliseconds = (long)this.Factor;
121121
}
122122

123-
public TimeSpan ToTimeSpan() => TimeSpan.FromMilliseconds(this.Milliseconds);
124-
125123
public int CompareTo(Time other)
126124
{
127125
if (other == null) return 1;
@@ -142,6 +140,8 @@ public int CompareTo(Time other)
142140
public static bool operator !=(Time left, Time right) =>
143141
!object.ReferenceEquals(left, null) && !object.ReferenceEquals(right, null) && !left.Equals(right);
144142

143+
public TimeSpan ToTimeSpan() => TimeSpan.FromMilliseconds(this.Milliseconds);
144+
145145
public override string ToString()
146146
{
147147
if (this.Factor == null) return this.Milliseconds.ToString(CultureInfo.InvariantCulture);

Diff for: src/Nest/Document/Multiple/Reindex/ReindexObservable.cs

+1-1
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);

Diff for: src/Nest/_Generated/_Descriptors.generated.cs

+78-78
Large diffs are not rendered by default.

Diff for: src/Nest/_Generated/_Requests.generated.cs

+884-884
Large diffs are not rendered by default.

Diff for: src/Tests/Search/Search/SearchUrlTests.cs

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Tests.Framework;
44
using Tests.Framework.MockData;
55
using static Tests.Framework.UrlTester;
6+
using System;
67

78
namespace Tests.Search.Search
89
{
@@ -53,6 +54,13 @@ await POST("/_search")
5354
.RequestAsync(c=>c.SearchAsync<Project>(new SearchRequest<Project>(Nest.Indices.All, Types.All)))
5455
.RequestAsync(c=>c.SearchAsync<Project>(new SearchRequest()))
5556
;
57+
58+
await POST("/_search?scroll=1m")
59+
.Fluent(c=>c.Search<Project>(s=>s.AllTypes().AllIndices().Scroll(TimeSpan.FromMinutes(1))))
60+
.Request(c=>c.Search<Project>(new SearchRequest<Project>(Nest.Indices.All, Types.All) { Scroll = new Time(1, TimeUnit.Minute) }))
61+
.FluentAsync(c=>c.SearchAsync<Project>(s=>s.AllIndices().Type(Types.All).Scroll("1m")))
62+
.RequestAsync(c=>c.SearchAsync<Project>(new SearchRequest<Project>(Nest.Indices.All, Types.All) { Scroll = 60000 } ))
63+
;
5664
}
5765
}
5866
}

Diff for: src/Tests/tests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# mode either u (unit test), i (integration test) or m (mixed mode)
2-
mode: i
2+
mode: u
33
# the elasticsearch version that should be started
44
elasticsearch_version: 2.0.1
55
# whether we want to forcefully reseed on the node, if you are starting the tests with a node already running

0 commit comments

Comments
 (0)