Skip to content

added constructors to QueryPathBase #950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Nest/DSL/CountDescriptor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Elasticsearch.Net;
using Newtonsoft.Json;

Expand Down Expand Up @@ -28,6 +29,12 @@ public static void Update(ElasticsearchPathInfo<CountRequestParameters> pathInfo

public partial class CountRequest : QueryPathBase<CountRequestParameters>, ICountRequest
{
public CountRequest() {}

public CountRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }

public CountRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }

public IQueryContainer Query { get; set; }

protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<CountRequestParameters> pathInfo)
Expand All @@ -39,6 +46,12 @@ protected override void UpdatePathInfo(IConnectionSettingsValues settings, Elast
public partial class CountRequest<T> : QueryPathBase<CountRequestParameters, T>, ICountRequest
where T : class
{
public CountRequest() {}

public CountRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }

public CountRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }

public IQueryContainer Query { get; set; }

protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<CountRequestParameters> pathInfo)
Expand Down
35 changes: 12 additions & 23 deletions src/Nest/DSL/DeleteByQueryDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,14 @@ public static void Update(ElasticsearchPathInfo<DeleteByQueryRequestParameters>

public partial class DeleteByQueryRequest : QueryPathBase<DeleteByQueryRequestParameters>, IDeleteByQueryRequest
{
public IQueryContainer Query { get; set; }
public DeleteByQueryRequest() {}

/// <summary>
/// Sents a delete query to _all indices
/// </summary>
public DeleteByQueryRequest()
{
this.AllIndices = true;
this.AllTypes = true;
}

public DeleteByQueryRequest(IndexNameMarker index, TypeNameMarker type = null)
{
this.Indices = new [] { index };
if (type != null)
this.Types = new[] { type };
else this.AllTypes = true;
}
public DeleteByQueryRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }

public DeleteByQueryRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }

public IQueryContainer Query { get; set; }

public DeleteByQueryRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null)
{
this.Indices = indices;
this.AllTypes = !types.HasAny();
this.Types = types;
}

protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<DeleteByQueryRequestParameters> pathInfo)
{
Expand All @@ -68,6 +51,12 @@ protected override void UpdatePathInfo(IConnectionSettingsValues settings, Elast

public partial class DeleteByQueryRequest<T> : QueryPathBase<DeleteByQueryRequestParameters, T>, IDeleteByQueryRequest where T : class
{
public DeleteByQueryRequest() {}

public DeleteByQueryRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }

public DeleteByQueryRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }

public IQueryContainer Query { get; set; }

protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<DeleteByQueryRequestParameters> pathInfo)
Expand Down
38 changes: 38 additions & 0 deletions src/Nest/DSL/Paths/QueryPathDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,26 @@ public static void SetRouteParameters<TParameters, T>(
public abstract class QueryPathBase<TParameters> : BasePathRequest<TParameters>, IQueryPath<TParameters>
where TParameters : IRequestParameters, new()
{
protected QueryPathBase()
{
this.AllTypes = true;
}

protected QueryPathBase(IndexNameMarker index, TypeNameMarker type = null)
{
this.Indices = new [] { index };
if (type != null)
this.Types = new[] { type };
else this.AllTypes = true;
}

protected QueryPathBase(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null)
{
this.Indices = indices;
this.AllTypes = !types.HasAny();
this.Types = types;
}


protected override void SetRouteParameters(IConnectionSettingsValues settings, ElasticsearchPathInfo<TParameters> pathInfo)
{
Expand All @@ -94,6 +114,24 @@ public abstract class QueryPathBase<TParameters, T> : QueryPathBase<TParameters>
where TParameters : IRequestParameters, new()
where T : class
{
protected QueryPathBase()
{
this.AllIndices = false;
this.AllTypes = false;
}

protected QueryPathBase(IndexNameMarker index, TypeNameMarker type = null)
{
this.Indices = new [] { index };
if (type != null)
this.Types = new[] { type };
}

protected QueryPathBase(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null)
{
this.Indices = indices;
this.Types = types;
}

protected override void SetRouteParameters(IConnectionSettingsValues settings, ElasticsearchPathInfo<TParameters> pathInfo)
{
Expand Down
12 changes: 12 additions & 0 deletions src/Nest/DSL/SearchDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ public static void Update(IConnectionSettingsValues settings, ElasticsearchPathI

public partial class SearchRequest : QueryPathBase<SearchRequestParameters>, ISearchRequest
{
public SearchRequest() {}

public SearchRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }

public SearchRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }

private Type _clrType { get; set; }
Type ISearchRequest.ClrType { get { return _clrType; } }

Expand Down Expand Up @@ -186,6 +192,12 @@ protected override void UpdatePathInfo(IConnectionSettingsValues settings, Elast
public partial class SearchRequest<T> : QueryPathBase<SearchRequestParameters, T>, ISearchRequest
where T : class
{
public SearchRequest() {}

public SearchRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }

public SearchRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }

protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<SearchRequestParameters> pathInfo)
{
SearchPathInfo.Update(settings,pathInfo, this);
Expand Down
12 changes: 12 additions & 0 deletions src/Nest/DSL/SearchShardsDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public static void Update(IConnectionSettingsValues settings, ElasticsearchPathI

public partial class SearchShardsRequest : QueryPathBase<SearchShardsRequestParameters>, ISearchShardsRequest
{
public SearchShardsRequest() {}

public SearchShardsRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }

public SearchShardsRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }

protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<SearchShardsRequestParameters> pathInfo)
{
SearchShardsPathInfo.Update(settings, pathInfo, this);
Expand All @@ -36,6 +42,12 @@ protected override void UpdatePathInfo(IConnectionSettingsValues settings, Elast
public partial class SearchShardsRequest<T> : QueryPathBase<SearchShardsRequestParameters, T>, ISearchShardsRequest
where T : class
{
public SearchShardsRequest() {}

public SearchShardsRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }

public SearchShardsRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }

protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<SearchShardsRequestParameters> pathInfo)
{
SearchShardsPathInfo.Update(settings,pathInfo, this);
Expand Down
18 changes: 16 additions & 2 deletions src/Nest/DSL/ValidateQueryDescriptor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Elasticsearch.Net;
using Newtonsoft.Json;

Expand Down Expand Up @@ -29,7 +30,13 @@ public static void Update(ElasticsearchPathInfo<ValidateQueryRequestParameters>

public partial class ValidateQueryRequest : QueryPathBase<ValidateQueryRequestParameters>, IValidateQueryRequest
{
public IQueryContainer Query { get; set; }
public ValidateQueryRequest() {}

public ValidateQueryRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }

public ValidateQueryRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }

public IQueryContainer Query { get; set; }

protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<ValidateQueryRequestParameters> pathInfo)
{
Expand All @@ -40,7 +47,14 @@ protected override void UpdatePathInfo(IConnectionSettingsValues settings, Elast
public partial class ValidateQueryRequest<T> : QueryPathBase<ValidateQueryRequestParameters, T>, IValidateQueryRequest<T>
where T : class
{
public IQueryContainer Query { get; set; }

public ValidateQueryRequest() {}

public ValidateQueryRequest(IndexNameMarker index, TypeNameMarker type = null) : base(index, type) { }

public ValidateQueryRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameMarker> types = null) : base(indices, types) { }

public IQueryContainer Query { get; set; }

protected override void UpdatePathInfo(IConnectionSettingsValues settings, ElasticsearchPathInfo<ValidateQueryRequestParameters> pathInfo)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Nest/ExposedInternals/ElasticInferrer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public string DefaultIndex
{
get
{
return (this._connectionSettings == null) ? string.Empty : this._connectionSettings.DefaultIndex;
var index = (this._connectionSettings == null) ? string.Empty : this._connectionSettings.DefaultIndex;
return index.IsNullOrEmpty() ? "_all" : index;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<Compile Include="..\..\Elasticsearch.Net\Extensions\TypeExtensions.cs">
<Link>LinkedExtensions\TypeExtensions.cs</Link>
</Compile>
<Compile Include="Aggregations\CombinationTests.cs" />
<Compile Include="Aggregations\NestedBucketAggregationTests.cs" />
<Compile Include="Aggregations\BucketAggregationTests.cs" />
<Compile Include="Aggregations\SingleBucketAggregationTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public DeleteByQueryRequestTests()

var request = new DeleteByQueryRequest()
{
AllIndices = true,
AllowNoIndices = true,
ExpandWildcards = ExpandWildcards.Closed,
Query = query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void Untyped_Defaults()
var status = this._client.DeleteByQuery(new DeleteByQueryRequest())
.ConnectionStatus;

status.RequestUrl.Should().EndWith("/_all/_query");
status.RequestUrl.Should().EndWith("/nest_test_data/_query");
status.RequestMethod.Should().Be("DELETE");
}

Expand Down