Skip to content

Commit 182d194

Browse files
committed
Term() on filter now generic on argument like Term() on query, saves on ToString()'ing in client's code. related to #347
1 parent 93c46df commit 182d194

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

Diff for: src/Nest.Tests.Integration/Integration/Filter/AndOrNotFilterTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ public void TestOrFilter()
8383
public void TestNotFilter()
8484
{
8585
this.DoFilterTest(
86-
f => f.Not(n => n.Term(o => o.Id, (_LookFor.Id + 1).ToString())),
86+
f => f.Not(n => n.Term(o => o.Id, (_LookFor.Id + 1))),
8787
_LookFor,
8888
true);
8989

9090
this.DoFilterTest(
91-
f => f.Not(n => n.Term(o => o.Id, _LookFor.Id.ToString())),
91+
f => f.Not(n => n.Term(o => o.Id, _LookFor.Id)),
9292
_LookFor,
9393
false);
9494
}

Diff for: src/Nest.Tests.Integration/IntegrationTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void DoFilterTest(Func<FilterDescriptor<ElasticSearchProject>, Nest.BaseF
3535

3636
var results = this._client.Search<ElasticSearchProject>(
3737
s => s.Filter(ff => ff.And(
38-
f => f.Term(e => e.Id, project.Id.ToString()),
38+
f => f.Term(e => e.Id, project.Id),
3939
filter
4040
))
4141
);

Diff for: src/Nest/DSL/FilterDescriptor.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ public BaseFilter Prefix(string field, string prefix)
675675
/// Filters documents that have fields that contain a term (not analyzed).
676676
/// Similar to term query, except that it acts as a filter
677677
/// </summary>
678-
public BaseFilter Term(Expression<Func<T, object>> fieldDescriptor, string term)
678+
public BaseFilter Term<K>(Expression<Func<T, K>> fieldDescriptor, K term)
679679
{
680680
var field = new PropertyNameResolver().Resolve(fieldDescriptor);
681681
return this.Term(field, term);
@@ -684,10 +684,12 @@ public BaseFilter Term(Expression<Func<T, object>> fieldDescriptor, string term)
684684
/// Filters documents that have fields that contain a term (not analyzed).
685685
/// Similar to term query, except that it acts as a filter
686686
/// </summary>
687-
public BaseFilter Term(string field, string term)
687+
public BaseFilter Term<K>(string field, K term)
688688
{
689-
if (term.IsNullOrEmpty() || field.IsNullOrEmpty())
689+
var t = new Term() { Field = field, Value = (object)term };
690+
if (t.IsConditionless)
690691
return CreateConditionlessFilterDescriptor("term", new { term = term, field = field });
692+
691693
return this.SetDictionary("term", field, term, (d, b) =>
692694
{
693695
b.TermFilter = d;

Diff for: src/Nest/DSL/IFilterDescriptor.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ interface IFilterDescriptor<T>
4141
BaseFilter Query(Func<QueryDescriptor<T>, BaseQuery> querySelector);
4242
BaseFilter Range(Action<RangeFilterDescriptor<T>> rangeSelector);
4343
BaseFilter Script(Action<ScriptFilterDescriptor> scriptSelector);
44-
BaseFilter Term(Expression<Func<T, object>> fieldDescriptor, string term);
45-
BaseFilter Term(string field, string term);
44+
BaseFilter Term<K>(Expression<Func<T, K>> fieldDescriptor, K term);
45+
BaseFilter Term<K>(string field, K term);
4646
BaseFilter Terms(Expression<Func<T, object>> fieldDescriptor, IEnumerable<string> terms, TermsExecution? Execution = null);
4747
BaseFilter Terms(string field, IEnumerable<string> terms, TermsExecution? Execution = null);
4848
BaseFilter Type(string type);

0 commit comments

Comments
 (0)