Skip to content

Commit d765168

Browse files
author
Moran
committed
Search overload that accepts SearchDescriptor<T>
1 parent a3f0413 commit d765168

File tree

2 files changed

+47
-55
lines changed

2 files changed

+47
-55
lines changed

src/Nest/ElasticClient-Search.cs

Lines changed: 46 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
using Nest.FactoryDsl;
33
using System.Diagnostics;
44

5-
namespace Nest
6-
{
7-
public partial class ElasticClient
5+
namespace Nest
6+
{
7+
public partial class ElasticClient
88
{
99

1010
/// <summary>
1111
/// Search using dynamic as its return type.
1212
/// </summary>
1313
public IQueryResponse<dynamic> Search(
14-
SearchBuilder searchBuilder,
14+
SearchBuilder searchBuilder,
1515
string index = null,
1616
string type = null,
1717
string routing = null,
@@ -58,62 +58,53 @@ public IQueryResponse<T> Search<T>(SearchBuilder searchBuilder,
5858
ConnectionStatus status = this.Connection.PostSync(path, query);
5959
var r = this.ToParsedResponse<QueryResponse<T>>(status);
6060
return r;
61-
}
62-
63-
64-
/// <summary>
65-
/// Search using dynamic as its return type.
66-
/// </summary>
67-
public IQueryResponse<dynamic> Search(Func<SearchDescriptor<dynamic>, SearchDescriptor<dynamic>> searcher)
68-
{
69-
var search = new SearchDescriptor<dynamic>();
61+
}
62+
63+
64+
/// <summary>
65+
/// Search using dynamic as its return type.
66+
/// </summary>
67+
public IQueryResponse<dynamic> Search(Func<SearchDescriptor<dynamic>, SearchDescriptor<dynamic>> searcher)
68+
{
69+
var search = new SearchDescriptor<dynamic>();
7070
var descriptor = searcher(search);
71-
var path = this.PathResolver.GetSearchPathForDynamic(descriptor);
72-
var query = this.Serialize(descriptor);
73-
74-
ConnectionStatus status = this.Connection.PostSync(path, query);
75-
var r = this.ToParsedResponse<QueryResponse<dynamic>>(status);
76-
return r;
77-
}
78-
/// <summary>
79-
/// Search using T as the return type
80-
/// </summary>
81-
public IQueryResponse<T> Search<T>(Func<SearchDescriptor<T>, SearchDescriptor<T>> searcher) where T : class
71+
var path = this.PathResolver.GetSearchPathForDynamic(descriptor);
72+
var query = this.Serialize(descriptor);
73+
74+
ConnectionStatus status = this.Connection.PostSync(path, query);
75+
var r = this.ToParsedResponse<QueryResponse<dynamic>>(status);
76+
return r;
77+
}
78+
79+
/// <summary>
80+
/// Search using T as the return type
81+
/// </summary>
82+
public IQueryResponse<T> Search<T>(Func<SearchDescriptor<T>, SearchDescriptor<T>> searcher) where T : class
8283
{
83-
var sw2 = new Stopwatch(); sw2.Start();
84-
var sw = new Stopwatch();
85-
sw.Start();
86-
var search = new SearchDescriptor<T>();
84+
var search = new SearchDescriptor<T>();
8785
var descriptor = searcher(search);
88-
var xx = sw.Elapsed;
89-
sw.Restart();
86+
return Search(descriptor);
87+
}
88+
89+
public IQueryResponse<T> Search<T>(SearchDescriptor<T> descriptor) where T : class
90+
{
9091
var query = this.Serialize(descriptor);
91-
var xY = sw.Elapsed;
92-
sw.Restart();
9392
var path = this.PathResolver.GetSearchPathForTyped(descriptor);
94-
var xxx = sw.Elapsed;
95-
sw.Restart();
93+
var status = this.Connection.PostSync(path, query);
94+
return this.ToParsedResponse<QueryResponse<T>>(status);
95+
}
96+
97+
/// <summary>
98+
/// Search using T as the return type, string based.
99+
/// </summary>
100+
[Obsolete("Deprecated but will never be removed. Found a bug in the DSL? https://github.com/Mpdreamz/NEST/issues")]
101+
public IQueryResponse<T> SearchRaw<T>(string query) where T : class
102+
{
103+
var descriptor = new SearchDescriptor<T>();
104+
var path = this.PathResolver.GetSearchPathForTyped(descriptor);
96105
ConnectionStatus status = this.Connection.PostSync(path, query);
97-
var xxxx = sw.Elapsed;
98-
sw.Restart();
99106
var r = this.ToParsedResponse<QueryResponse<T>>(status);
100-
var xxxxx = sw.Elapsed;
101-
sw.Restart();
102-
sw2.Stop();
103-
var total = sw2.Elapsed;
104-
return r;
105-
}
106-
/// <summary>
107-
/// Search using T as the return type, string based.
108-
/// </summary>
109-
[Obsolete("Deprecated but will never be removed. Found a bug in the DSL? https://github.com/Mpdreamz/NEST/issues")]
110-
public IQueryResponse<T> SearchRaw<T>(string query) where T : class
111-
{
112-
var descriptor = new SearchDescriptor<T>();
113-
var path = this.PathResolver.GetSearchPathForTyped(descriptor);
114-
ConnectionStatus status = this.Connection.PostSync(path, query);
115-
var r = this.ToParsedResponse<QueryResponse<T>>(status);
116-
return r;
117-
}
118-
}
107+
return r;
108+
}
109+
}
119110
}

src/Nest/IElasticClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,5 +242,6 @@ IQueryResponse<T> Search<T>(SearchBuilder searchBuilder,
242242
ISettingsOperationResponse UpdateSettings(IndexSettings settings);
243243
ISettingsOperationResponse UpdateSettings(string index, IndexSettings settings);
244244
IElasticSearchVersionInfo VersionInfo { get; }
245+
IQueryResponse<T> Search<T>(SearchDescriptor<T> descriptor) where T : class;
245246
}
246247
}

0 commit comments

Comments
 (0)