From 087ac47b0ab4309963758069be772f6bf3da63de Mon Sep 17 00:00:00 2001 From: Jaap Taal Date: Wed, 12 Jun 2013 14:57:24 +0200 Subject: [PATCH] Added overload to type filter --- .../Filter/ConditionLess/ConditionLessTests.cs | 4 +--- src/Nest/DSL/Filter/TypeFilter.cs | 3 ++- src/Nest/DSL/FilterDescriptor.cs | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Nest.Tests.Unit/Search/Filter/ConditionLess/ConditionLessTests.cs b/src/Nest.Tests.Unit/Search/Filter/ConditionLess/ConditionLessTests.cs index 9c50eaa4322..b2771cb949c 100644 --- a/src/Nest.Tests.Unit/Search/Filter/ConditionLess/ConditionLessTests.cs +++ b/src/Nest.Tests.Unit/Search/Filter/ConditionLess/ConditionLessTests.cs @@ -247,10 +247,8 @@ public void TermsTest() public void TypeTest() { this.DoConditionlessFilter(f => f.Type(string.Empty)); - this.DoConditionlessFilter(f => f.Type(null)); + this.DoConditionlessFilter(f => f.Type((string)null)); } - - } } diff --git a/src/Nest/DSL/Filter/TypeFilter.cs b/src/Nest/DSL/Filter/TypeFilter.cs index 518dcd0c123..6e8682d938f 100644 --- a/src/Nest/DSL/Filter/TypeFilter.cs +++ b/src/Nest/DSL/Filter/TypeFilter.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using Nest.Resolvers; using Newtonsoft.Json; namespace Nest @@ -18,6 +19,6 @@ internal override bool IsConditionless } [JsonProperty(PropertyName = "value")] - public string Value { get; set;} + public TypeNameMarker Value { get; set; } } } diff --git a/src/Nest/DSL/FilterDescriptor.cs b/src/Nest/DSL/FilterDescriptor.cs index a46f111c140..769dbe65c5c 100644 --- a/src/Nest/DSL/FilterDescriptor.cs +++ b/src/Nest/DSL/FilterDescriptor.cs @@ -549,6 +549,23 @@ public BaseFilter Type(string type) this.TypeFilter = filter; return new FilterDescriptor() { TypeFilter = filter }; } + + /// + /// Filters documents matching the provided document / mapping type. + /// Note, this filter can work even when the _type field is not indexed + /// (using the _uid field). + /// + public BaseFilter Type(Type type) + { + var filter = new TypeFilter { Value = type }; + if (filter.IsConditionless) + return CreateConditionlessFilterDescriptor("filter", filter); + + this.SetCacheAndName(filter); + this.TypeFilter = filter; + return new FilterDescriptor() { TypeFilter = filter }; + } + /// /// A filter that matches on all documents. ///