From fcbe37b4a225724ccdac04a43539227d3cbc58ef Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Wed, 23 Apr 2014 00:32:03 -0400 Subject: [PATCH 1/5] Added TermVector support --- src/Nest/DSL/TermVectorDescriptor.cs | 20 +++++++++++++ src/Nest/DSL/_Descriptors.generated.cs | 22 +++++++------- .../Domain/Responses/TermVectorResponse.cs | 29 ++++++++++++++++++ src/Nest/Domain/TermVector/FieldStatistics.cs | 21 +++++++++++++ src/Nest/Domain/TermVector/TermVector.cs | 18 +++++++++++ src/Nest/Domain/TermVector/TermVectorTerm.cs | 24 +++++++++++++++ src/Nest/Domain/TermVector/Token.cs | 24 +++++++++++++++ src/Nest/ElasticClient-TermVector.cs | 30 +++++++++++++++++++ src/Nest/Enums/TermVectorOption.cs | 4 +-- src/Nest/IElasticClient.cs | 2 ++ src/Nest/Nest.csproj | 7 +++++ 11 files changed, 188 insertions(+), 13 deletions(-) create mode 100644 src/Nest/DSL/TermVectorDescriptor.cs create mode 100644 src/Nest/Domain/Responses/TermVectorResponse.cs create mode 100644 src/Nest/Domain/TermVector/FieldStatistics.cs create mode 100644 src/Nest/Domain/TermVector/TermVector.cs create mode 100644 src/Nest/Domain/TermVector/TermVectorTerm.cs create mode 100644 src/Nest/Domain/TermVector/Token.cs create mode 100644 src/Nest/ElasticClient-TermVector.cs diff --git a/src/Nest/DSL/TermVectorDescriptor.cs b/src/Nest/DSL/TermVectorDescriptor.cs new file mode 100644 index 00000000000..d23ab72308b --- /dev/null +++ b/src/Nest/DSL/TermVectorDescriptor.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Elasticsearch.Net; + +namespace Nest +{ + public partial class TermvectorDescriptor : DocumentPathDescriptorBase, T, TermvectorQueryString> + , IPathInfo where T : class + { + ElasticsearchPathInfo IPathInfo.ToPathInfo(IConnectionSettingsValues settings) + { + var pathInfo = base.ToPathInfo(settings, this._QueryString); + pathInfo.HttpMethod = PathInfoHttpMethod.GET; + + return pathInfo; + } + } +} diff --git a/src/Nest/DSL/_Descriptors.generated.cs b/src/Nest/DSL/_Descriptors.generated.cs index 7eec8941aff..4e66b5c1ff9 100644 --- a/src/Nest/DSL/_Descriptors.generated.cs +++ b/src/Nest/DSL/_Descriptors.generated.cs @@ -4761,13 +4761,13 @@ public SuggestDescriptor Source(string source) ///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/docs-termvectors.html /// /// - public partial class TermvectorDescriptor + public partial class TermvectorDescriptor { internal TermvectorQueryString _QueryString = new TermvectorQueryString(); ///Specifies if total term frequency and document frequency should be returned. - public TermvectorDescriptor TermStatistics(bool term_statistics = true) + public TermvectorDescriptor TermStatistics(bool term_statistics = true) { this._QueryString.TermStatistics(term_statistics); return this; @@ -4775,7 +4775,7 @@ public TermvectorDescriptor TermStatistics(bool term_statistics = true) ///Specifies if document count, sum of document frequencies and sum of total term frequencies should be returned. - public TermvectorDescriptor FieldStatistics(bool field_statistics = true) + public TermvectorDescriptor FieldStatistics(bool field_statistics = true) { this._QueryString.FieldStatistics(field_statistics); return this; @@ -4783,7 +4783,7 @@ public TermvectorDescriptor FieldStatistics(bool field_statistics = true) ///A comma-separated list of fields to return. - public TermvectorDescriptor Fields(params string[] fields) + public TermvectorDescriptor Fields(params string[] fields) { this._QueryString.Fields(fields); return this; @@ -4791,7 +4791,7 @@ public TermvectorDescriptor Fields(params string[] fields) ///A comma-separated list of fields to return. - public TermvectorDescriptor Fields(params Expression>[] typedPathLookups) where T : class + public TermvectorDescriptor Fields(params Expression>[] typedPathLookups) { if (!typedPathLookups.HasAny()) return this; @@ -4802,7 +4802,7 @@ public TermvectorDescriptor Fields(params Expression>[] typed ///Specifies if term offsets should be returned. - public TermvectorDescriptor Offsets(bool offsets = true) + public TermvectorDescriptor Offsets(bool offsets = true) { this._QueryString.Offsets(offsets); return this; @@ -4810,7 +4810,7 @@ public TermvectorDescriptor Offsets(bool offsets = true) ///Specifies if term positions should be returned. - public TermvectorDescriptor Positions(bool positions = true) + public TermvectorDescriptor Positions(bool positions = true) { this._QueryString.Positions(positions); return this; @@ -4818,7 +4818,7 @@ public TermvectorDescriptor Positions(bool positions = true) ///Specifies if term payloads should be returned. - public TermvectorDescriptor Payloads(bool payloads = true) + public TermvectorDescriptor Payloads(bool payloads = true) { this._QueryString.Payloads(payloads); return this; @@ -4826,7 +4826,7 @@ public TermvectorDescriptor Payloads(bool payloads = true) ///Specify the node or shard the operation should be performed on (default: random). - public TermvectorDescriptor Preference(string preference) + public TermvectorDescriptor Preference(string preference) { this._QueryString.Preference(preference); return this; @@ -4834,7 +4834,7 @@ public TermvectorDescriptor Preference(string preference) ///Specific routing value. - public TermvectorDescriptor Routing(string routing) + public TermvectorDescriptor Routing(string routing) { this._QueryString.Routing(routing); return this; @@ -4842,7 +4842,7 @@ public TermvectorDescriptor Routing(string routing) ///Parent id of documents. - public TermvectorDescriptor Parent(string parent) + public TermvectorDescriptor Parent(string parent) { this._QueryString.Parent(parent); return this; diff --git a/src/Nest/Domain/Responses/TermVectorResponse.cs b/src/Nest/Domain/Responses/TermVectorResponse.cs new file mode 100644 index 00000000000..8968a28af49 --- /dev/null +++ b/src/Nest/Domain/Responses/TermVectorResponse.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Newtonsoft.Json; + +namespace Nest +{ + public interface ITermVectorResponse : IResponse + { + bool Found { get; } + IDictionary TermVectors { get; } + } + + [JsonObject] + public class TermVectorResponse : BaseResponse, ITermVectorResponse + { + public TermVectorResponse() + { + IsValid = true; + } + + [JsonProperty("found")] + public bool Found { get; internal set; } + + [JsonProperty("term_vectors")] + public IDictionary TermVectors { get; internal set; } + } +} diff --git a/src/Nest/Domain/TermVector/FieldStatistics.cs b/src/Nest/Domain/TermVector/FieldStatistics.cs new file mode 100644 index 00000000000..1e98deb5825 --- /dev/null +++ b/src/Nest/Domain/TermVector/FieldStatistics.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Newtonsoft.Json; + +namespace Nest +{ + [JsonObject] + public class FieldStatistics + { + [JsonProperty("doc_count")] + public int DocumentCount { get; internal set; } + + [JsonProperty("sum_doc_freq")] + public int SumOfDocumentFrequencies { get; internal set; } + + [JsonProperty("sum_ttf")] + public int SumOfTotalTermFrequencies { get; internal set; } + } +} diff --git a/src/Nest/Domain/TermVector/TermVector.cs b/src/Nest/Domain/TermVector/TermVector.cs new file mode 100644 index 00000000000..bbe1b55ed3d --- /dev/null +++ b/src/Nest/Domain/TermVector/TermVector.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Newtonsoft.Json; + +namespace Nest +{ + [JsonObject] + public class TermVector + { + [JsonProperty("field_statistics")] + public FieldStatistics FieldStatistics { get; internal set; } + + [JsonProperty("terms")] + public IDictionary Terms { get; internal set; } + } +} diff --git a/src/Nest/Domain/TermVector/TermVectorTerm.cs b/src/Nest/Domain/TermVector/TermVectorTerm.cs new file mode 100644 index 00000000000..1c5486c3cd4 --- /dev/null +++ b/src/Nest/Domain/TermVector/TermVectorTerm.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Newtonsoft.Json; + +namespace Nest +{ + [JsonObject] + public class TermVectorTerm + { + [JsonProperty("doc_freq")] + public int DocumentFrequency { get; internal set; } + + [JsonProperty("term_freq")] + public int TermFrequency { get; internal set; } + + [JsonProperty("tokens")] + public IEnumerable Tokens { get; internal set; } + + [JsonProperty("ttf")] + public int TotalTermFrequency { get; internal set; } + } +} diff --git a/src/Nest/Domain/TermVector/Token.cs b/src/Nest/Domain/TermVector/Token.cs new file mode 100644 index 00000000000..e6f31861362 --- /dev/null +++ b/src/Nest/Domain/TermVector/Token.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Newtonsoft.Json; + +namespace Nest +{ + [JsonObject] + public class Token + { + [JsonProperty("end_offset")] + public int EndOffset { get; internal set; } + + [JsonProperty("payload")] + public string Payload { get; internal set; } + + [JsonProperty("position")] + public int Position { get; internal set; } + + [JsonProperty("start_offset")] + public int StartOffset { get; internal set; } + } +} diff --git a/src/Nest/ElasticClient-TermVector.cs b/src/Nest/ElasticClient-TermVector.cs new file mode 100644 index 00000000000..c0fdc83e09b --- /dev/null +++ b/src/Nest/ElasticClient-TermVector.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Elasticsearch.Net; + +namespace Nest +{ + public partial class ElasticClient + { + public ITermVectorResponse TermVector(Func, TermvectorDescriptor> termVectorSelector) + where T : class + { + return this.Dispatch, TermvectorQueryString, TermVectorResponse>( + termVectorSelector, + (p, d) => this.RawDispatch.TermvectorDispatch(p, d) + ); + } + + public Task TermVectorAsync(Func, TermvectorDescriptor> termVectorSelector) + where T : class + { + return this.DispatchAsync, TermvectorQueryString, TermVectorResponse, ITermVectorResponse>( + termVectorSelector, + (p, d) => this.RawDispatch.TermvectorDispatchAsync(p, d) + ); + } + } +} diff --git a/src/Nest/Enums/TermVectorOption.cs b/src/Nest/Enums/TermVectorOption.cs index 9f328217a77..99618bc6688 100644 --- a/src/Nest/Enums/TermVectorOption.cs +++ b/src/Nest/Enums/TermVectorOption.cs @@ -14,7 +14,7 @@ public enum TermVectorOption yes, with_offsets, with_positions, - with_positions_offsets - + with_positions_offsets, + with_positions_offsets_payloads } } diff --git a/src/Nest/IElasticClient.cs b/src/Nest/IElasticClient.cs index 0d2b723dc17..ac728954a4d 100644 --- a/src/Nest/IElasticClient.cs +++ b/src/Nest/IElasticClient.cs @@ -151,5 +151,7 @@ Task IndexManyAsync(IEnumerable objects, string index = nul IStatusResponse Status(Func selector = null); Task StatusAsync(Func selector = null); + ITermVectorResponse TermVector(Func, TermvectorDescriptor> termVectorSelector) where T : class; + Task TermVectorAsync(Func, TermvectorDescriptor> termVectorSelector) where T : class; } } diff --git a/src/Nest/Nest.csproj b/src/Nest/Nest.csproj index b66d9164e95..6ec2c6afe97 100644 --- a/src/Nest/Nest.csproj +++ b/src/Nest/Nest.csproj @@ -127,6 +127,11 @@ + + + + + @@ -182,6 +187,7 @@ + @@ -203,6 +209,7 @@ + From 0ec0cd8fa6b20a31d3c9fb4c95e5d9bb48ccb2d8 Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Sat, 26 Apr 2014 13:38:11 -0400 Subject: [PATCH 2/5] XML doc tags for TermVector methods --- src/Nest/IElasticClient.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Nest/IElasticClient.cs b/src/Nest/IElasticClient.cs index de38bda2d7e..6faec994980 100644 --- a/src/Nest/IElasticClient.cs +++ b/src/Nest/IElasticClient.cs @@ -1034,9 +1034,23 @@ Task IndexManyAsync(IEnumerable objects, string index = nul /// An optional descriptor that further describes the status operation, i.e limiting it to certain indices Task StatusAsync(Func selector = null); + /// + /// Returns information and statistics on terms in the fields of a particular document as stored in the index. + /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-termvectors.html + /// + /// + /// + /// ITermVectorResponse TermVector(Func, TermvectorDescriptor> termVectorSelector) where T : class; + /// + /// Returns information and statistics on terms in the fields of a particular document as stored in the index. + /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-termvectors.html + /// + /// + /// + /// Task TermVectorAsync(Func, TermvectorDescriptor> termVectorSelector) where T : class; From c45bfa1c599fd17d563521b1a78d145c54fab354 Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Sat, 26 Apr 2014 15:47:49 -0400 Subject: [PATCH 3/5] Support for multi termvectors --- src/Nest/DSL/MultiTermVectorsDescriptor.cs | 20 +++++++++++++ src/Nest/DSL/_Descriptors.generated.cs | 24 +++++++-------- .../Responses/MultiTermVectorResponse.cs | 25 ++++++++++++++++ src/Nest/ElasticClient-MultiTermVectors.cs | 30 +++++++++++++++++++ src/Nest/IElasticClient.cs | 18 +++++++++++ src/Nest/Nest.csproj | 3 ++ 6 files changed, 108 insertions(+), 12 deletions(-) create mode 100644 src/Nest/DSL/MultiTermVectorsDescriptor.cs create mode 100644 src/Nest/Domain/Responses/MultiTermVectorResponse.cs create mode 100644 src/Nest/ElasticClient-MultiTermVectors.cs diff --git a/src/Nest/DSL/MultiTermVectorsDescriptor.cs b/src/Nest/DSL/MultiTermVectorsDescriptor.cs new file mode 100644 index 00000000000..2e052a79495 --- /dev/null +++ b/src/Nest/DSL/MultiTermVectorsDescriptor.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Elasticsearch.Net; + +namespace Nest +{ + public partial class MtermvectorsDescriptor : DocumentPathDescriptorBase, T, MtermvectorsRequestParameters> + , IPathInfo where T : class + { + ElasticsearchPathInfo IPathInfo.ToPathInfo(IConnectionSettingsValues settings) + { + var pathInfo = base.ToPathInfo(settings, this._QueryString); + pathInfo.HttpMethod = PathInfoHttpMethod.POST; + + return pathInfo; + } + } +} diff --git a/src/Nest/DSL/_Descriptors.generated.cs b/src/Nest/DSL/_Descriptors.generated.cs index a73107274a2..6449c4e2b1f 100644 --- a/src/Nest/DSL/_Descriptors.generated.cs +++ b/src/Nest/DSL/_Descriptors.generated.cs @@ -4081,13 +4081,13 @@ public MultiSearchDescriptor SearchType(SearchTypeOptions search_type) ///http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/docs-multi-termvectors.html /// /// - public partial class MtermvectorsDescriptor + public partial class MtermvectorsDescriptor { internal MtermvectorsRequestParameters _QueryString = new MtermvectorsRequestParameters(); ///A comma-separated list of documents ids. You must define ids as parameter or set "ids" or "docs" in the request body - public MtermvectorsDescriptor Ids(params string[] ids) + public MtermvectorsDescriptor Ids(params string[] ids) { this._QueryString.Ids(ids); return this; @@ -4095,7 +4095,7 @@ public MtermvectorsDescriptor Ids(params string[] ids) ///Specifies if total term frequency and document frequency should be returned. Applies to all returned documents unless otherwise specified in body "params" or "docs". - public MtermvectorsDescriptor TermStatistics(bool term_statistics = true) + public MtermvectorsDescriptor TermStatistics(bool term_statistics = true) { this._QueryString.TermStatistics(term_statistics); return this; @@ -4103,7 +4103,7 @@ public MtermvectorsDescriptor TermStatistics(bool term_statistics = true) ///Specifies if document count, sum of document frequencies and sum of total term frequencies should be returned. Applies to all returned documents unless otherwise specified in body "params" or "docs". - public MtermvectorsDescriptor FieldStatistics(bool field_statistics = true) + public MtermvectorsDescriptor FieldStatistics(bool field_statistics = true) { this._QueryString.FieldStatistics(field_statistics); return this; @@ -4111,7 +4111,7 @@ public MtermvectorsDescriptor FieldStatistics(bool field_statistics = true) ///A comma-separated list of fields to return. Applies to all returned documents unless otherwise specified in body "params" or "docs". - public MtermvectorsDescriptor Fields(params string[] fields) + public MtermvectorsDescriptor Fields(params string[] fields) { this._QueryString.Fields(fields); return this; @@ -4119,7 +4119,7 @@ public MtermvectorsDescriptor Fields(params string[] fields) ///A comma-separated list of fields to return. Applies to all returned documents unless otherwise specified in body "params" or "docs". - public MtermvectorsDescriptor Fields(params Expression>[] typedPathLookups) where T : class + public MtermvectorsDescriptor Fields(params Expression>[] typedPathLookups) { if (!typedPathLookups.HasAny()) return this; @@ -4130,7 +4130,7 @@ public MtermvectorsDescriptor Fields(params Expression>[] typ ///Specifies if term offsets should be returned. Applies to all returned documents unless otherwise specified in body "params" or "docs". - public MtermvectorsDescriptor Offsets(bool offsets = true) + public MtermvectorsDescriptor Offsets(bool offsets = true) { this._QueryString.Offsets(offsets); return this; @@ -4138,7 +4138,7 @@ public MtermvectorsDescriptor Offsets(bool offsets = true) ///Specifies if term positions should be returned. Applies to all returned documents unless otherwise specified in body "params" or "docs". - public MtermvectorsDescriptor Positions(bool positions = true) + public MtermvectorsDescriptor Positions(bool positions = true) { this._QueryString.Positions(positions); return this; @@ -4146,7 +4146,7 @@ public MtermvectorsDescriptor Positions(bool positions = true) ///Specifies if term payloads should be returned. Applies to all returned documents unless otherwise specified in body "params" or "docs". - public MtermvectorsDescriptor Payloads(bool payloads = true) + public MtermvectorsDescriptor Payloads(bool payloads = true) { this._QueryString.Payloads(payloads); return this; @@ -4154,7 +4154,7 @@ public MtermvectorsDescriptor Payloads(bool payloads = true) ///Specify the node or shard the operation should be performed on (default: random) .Applies to all returned documents unless otherwise specified in body "params" or "docs". - public MtermvectorsDescriptor Preference(string preference) + public MtermvectorsDescriptor Preference(string preference) { this._QueryString.Preference(preference); return this; @@ -4162,7 +4162,7 @@ public MtermvectorsDescriptor Preference(string preference) ///Specific routing value. Applies to all returned documents unless otherwise specified in body "params" or "docs". - public MtermvectorsDescriptor Routing(string routing) + public MtermvectorsDescriptor Routing(string routing) { this._QueryString.Routing(routing); return this; @@ -4170,7 +4170,7 @@ public MtermvectorsDescriptor Routing(string routing) ///Parent id of documents. Applies to all returned documents unless otherwise specified in body "params" or "docs". - public MtermvectorsDescriptor Parent(string parent) + public MtermvectorsDescriptor Parent(string parent) { this._QueryString.Parent(parent); return this; diff --git a/src/Nest/Domain/Responses/MultiTermVectorResponse.cs b/src/Nest/Domain/Responses/MultiTermVectorResponse.cs new file mode 100644 index 00000000000..fb95877b909 --- /dev/null +++ b/src/Nest/Domain/Responses/MultiTermVectorResponse.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Newtonsoft.Json; + +namespace Nest +{ + public interface IMultiTermVectorResponse : IResponse + { + IEnumerable Documents { get; } + } + + [JsonObject] + public class MultiTermVectorResponse : BaseResponse, IMultiTermVectorResponse + { + public MultiTermVectorResponse() + { + IsValid = true; + } + + [JsonProperty("docs")] + public IEnumerable Documents { get; internal set; } + } +} diff --git a/src/Nest/ElasticClient-MultiTermVectors.cs b/src/Nest/ElasticClient-MultiTermVectors.cs new file mode 100644 index 00000000000..86e5f5fbbcc --- /dev/null +++ b/src/Nest/ElasticClient-MultiTermVectors.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Elasticsearch.Net; + +namespace Nest +{ + public partial class ElasticClient + { + public IMultiTermVectorResponse MultiTermVectors(Func, MtermvectorsDescriptor> multiTermVectorsSelector) + where T : class + { + return this.Dispatch, MtermvectorsRequestParameters, MultiTermVectorResponse>( + multiTermVectorsSelector, + (p, d) => this.RawDispatch.MtermvectorsDispatch(p, d) + ); + } + + public Task MultiTermVectorsAsync(Func, MtermvectorsDescriptor> multiTermVectorsSelector) + where T : class + { + return this.DispatchAsync, MtermvectorsRequestParameters, MultiTermVectorResponse, IMultiTermVectorResponse>( + multiTermVectorsSelector, + (p, d) => this.RawDispatch.MtermvectorsDispatchAsync(p, d) + ); + } + } +} diff --git a/src/Nest/IElasticClient.cs b/src/Nest/IElasticClient.cs index 6faec994980..d964d99cb35 100644 --- a/src/Nest/IElasticClient.cs +++ b/src/Nest/IElasticClient.cs @@ -1053,6 +1053,24 @@ ITermVectorResponse TermVector(Func, TermvectorDescri /// Task TermVectorAsync(Func, TermvectorDescriptor> termVectorSelector) where T : class; + + /// + /// Multi termvectors API allows to get multiple termvectors based on an index, type and id. + /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-multi-termvectors.html + /// + /// The type used to infer the default index and typename + /// The descriptor describing the multi termvectors operation + IMultiTermVectorResponse MultiTermVectors(Func, MtermvectorsDescriptor> multiTermVectorsSelector) + where T : class; + + /// + /// Multi termvectors API allows to get multiple termvectors based on an index, type and id. + /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-multi-termvectors.html + /// + /// The type used to infer the default index and typename + /// The descriptor describing the multi termvectors operation + Task MultiTermVectorsAsync(Func, MtermvectorsDescriptor> multiTermVectorsSelector) + where T : class; /// /// The suggest feature suggests similar looking terms based on a provided text by using a suggester. diff --git a/src/Nest/Nest.csproj b/src/Nest/Nest.csproj index 20707e9e2da..27acbf536ea 100644 --- a/src/Nest/Nest.csproj +++ b/src/Nest/Nest.csproj @@ -134,10 +134,12 @@ + + @@ -253,6 +255,7 @@ + From e6734d77349fa9b55f668936b43771fee8654939 Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Sun, 27 Apr 2014 14:50:57 -0400 Subject: [PATCH 4/5] Constructor initialization for collections in termvector response objects --- src/Nest/Domain/Responses/MultiTermVectorResponse.cs | 1 + src/Nest/Domain/Responses/TermVectorResponse.cs | 1 + src/Nest/Domain/TermVector/TermVector.cs | 5 +++++ src/Nest/Domain/TermVector/TermVectorTerm.cs | 5 +++++ 4 files changed, 12 insertions(+) diff --git a/src/Nest/Domain/Responses/MultiTermVectorResponse.cs b/src/Nest/Domain/Responses/MultiTermVectorResponse.cs index fb95877b909..3f8de58ee4d 100644 --- a/src/Nest/Domain/Responses/MultiTermVectorResponse.cs +++ b/src/Nest/Domain/Responses/MultiTermVectorResponse.cs @@ -17,6 +17,7 @@ public class MultiTermVectorResponse : BaseResponse, IMultiTermVectorResponse public MultiTermVectorResponse() { IsValid = true; + Documents = new List(); } [JsonProperty("docs")] diff --git a/src/Nest/Domain/Responses/TermVectorResponse.cs b/src/Nest/Domain/Responses/TermVectorResponse.cs index 8968a28af49..1e7c1850f08 100644 --- a/src/Nest/Domain/Responses/TermVectorResponse.cs +++ b/src/Nest/Domain/Responses/TermVectorResponse.cs @@ -18,6 +18,7 @@ public class TermVectorResponse : BaseResponse, ITermVectorResponse public TermVectorResponse() { IsValid = true; + TermVectors = new Dictionary(); } [JsonProperty("found")] diff --git a/src/Nest/Domain/TermVector/TermVector.cs b/src/Nest/Domain/TermVector/TermVector.cs index bbe1b55ed3d..90b66472933 100644 --- a/src/Nest/Domain/TermVector/TermVector.cs +++ b/src/Nest/Domain/TermVector/TermVector.cs @@ -9,6 +9,11 @@ namespace Nest [JsonObject] public class TermVector { + public TermVector() + { + Terms = new Dictionary(); + } + [JsonProperty("field_statistics")] public FieldStatistics FieldStatistics { get; internal set; } diff --git a/src/Nest/Domain/TermVector/TermVectorTerm.cs b/src/Nest/Domain/TermVector/TermVectorTerm.cs index 1c5486c3cd4..d05d88b1ebe 100644 --- a/src/Nest/Domain/TermVector/TermVectorTerm.cs +++ b/src/Nest/Domain/TermVector/TermVectorTerm.cs @@ -9,6 +9,11 @@ namespace Nest [JsonObject] public class TermVectorTerm { + public TermVectorTerm() + { + Tokens = new List(); + } + [JsonProperty("doc_freq")] public int DocumentFrequency { get; internal set; } From b078e5645596cb4d19aabc25a6963a3322bd21fe Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Sun, 27 Apr 2014 14:57:35 -0400 Subject: [PATCH 5/5] Added integration tests for TermVector and MultiTermVectors --- .../Core/TermVectors/MultiTermVectorsTests.cs | 45 ++++++++ .../Core/TermVectors/TermVectorTests.cs | 105 ++++++++++++++++++ .../IntegrationSetup.cs | 14 ++- .../Nest.Tests.Integration.csproj | 2 + 4 files changed, 162 insertions(+), 4 deletions(-) create mode 100644 src/Tests/Nest.Tests.Integration/Core/TermVectors/MultiTermVectorsTests.cs create mode 100644 src/Tests/Nest.Tests.Integration/Core/TermVectors/TermVectorTests.cs diff --git a/src/Tests/Nest.Tests.Integration/Core/TermVectors/MultiTermVectorsTests.cs b/src/Tests/Nest.Tests.Integration/Core/TermVectors/MultiTermVectorsTests.cs new file mode 100644 index 00000000000..87a6e93cbb4 --- /dev/null +++ b/src/Tests/Nest.Tests.Integration/Core/TermVectors/MultiTermVectorsTests.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using FluentAssertions; +using NUnit.Framework; +using Nest.Tests.MockData.Domain; + +namespace Nest.Tests.Integration.Core.TermVectors +{ + [TestFixture] + public class MultiTermVectorsTests : IntegrationTests + { + [Test] + public void MultiTermVectorsTest() + { + var result = _client.MultiTermVectors(s => s + .Fields(ep => ep.Content) + .Ids("1", "2")); + + result.IsValid.Should().BeTrue(); + + result.Documents.Should().NotBeNull(); + result.Documents.Count().Should().Be(2); + + foreach (var document in result.Documents) + { + document.TermVectors.Count().Should().Be(1); + document.TermVectors.First().Key.Should().Be("content"); + } + } + + [Test] + public void MultiTermVectorsNonExistentIdTest() + { + var result = _client.MultiTermVectors(s => s + .Ids("thisiddoesnotexist")); + + result.IsValid.Should().BeTrue(); + result.Documents.Count().Should().Be(1); + result.Documents.First().Found.Should().Be(false); + } + } +} diff --git a/src/Tests/Nest.Tests.Integration/Core/TermVectors/TermVectorTests.cs b/src/Tests/Nest.Tests.Integration/Core/TermVectors/TermVectorTests.cs new file mode 100644 index 00000000000..8a076b6d15b --- /dev/null +++ b/src/Tests/Nest.Tests.Integration/Core/TermVectors/TermVectorTests.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using FluentAssertions; +using NUnit.Framework; +using Nest.Tests.MockData.Domain; + +namespace Nest.Tests.Integration.Core.TermVectors +{ + [TestFixture] + public class TermVectorTests : IntegrationTests + { + [Test] + public void TermVectorDefaultsTest() + { + var result = _client.TermVector(s => s + .Id("1") + .Fields(ep => ep.Content)); + + result.IsValid.Should().BeTrue(); + result.Found.Should().BeTrue(); + result.TermVectors.Count().Should().Be(1); + + var contentTermVector = result.TermVectors["content"]; + contentTermVector.FieldStatistics.Should().NotBeNull(); + contentTermVector.FieldStatistics.DocumentCount.Should().BeGreaterOrEqualTo(1); + contentTermVector.FieldStatistics.SumOfDocumentFrequencies.Should().BeGreaterOrEqualTo(1); + contentTermVector.FieldStatistics.SumOfTotalTermFrequencies.Should().BeGreaterOrEqualTo(1); + + contentTermVector.Terms.Count.Should().BeGreaterOrEqualTo(1); + + var firstTerm = contentTermVector.Terms.First().Value; + firstTerm.Tokens.Should().NotBeNull(); + firstTerm.TotalTermFrequency.Should().Be(0); + firstTerm.DocumentFrequency.Should().Be(0); + } + + [Test] + public void TermVectorDefaultsWithTermStatisticsTest() + { + var result = _client.TermVector(s => s + .Id("1") + .Fields(ep => ep.Content) + .TermStatistics(true)); + + result.IsValid.Should().BeTrue(); + result.Found.Should().BeTrue(); + result.TermVectors.Count().Should().Be(1); + + var contentTermVector = result.TermVectors["content"]; + contentTermVector.FieldStatistics.Should().NotBeNull(); + contentTermVector.FieldStatistics.DocumentCount.Should().BeGreaterOrEqualTo(1); + contentTermVector.FieldStatistics.SumOfDocumentFrequencies.Should().BeGreaterOrEqualTo(1); + contentTermVector.FieldStatistics.SumOfTotalTermFrequencies.Should().BeGreaterOrEqualTo(1); + + contentTermVector.Terms.Count.Should().BeGreaterOrEqualTo(1); + + var firstTerm = contentTermVector.Terms.First().Value; + firstTerm.Tokens.Should().NotBeNull(); + firstTerm.TotalTermFrequency.Should().BeGreaterOrEqualTo(1); + firstTerm.DocumentFrequency.Should().BeGreaterOrEqualTo(1); + } + + [Test] + public void TermVectorNoFieldStatisticsTest() + { + var result = _client.TermVector(s => s + .Id("1") + .Fields(ep => ep.Content) + .FieldStatistics(false)); + + result.IsValid.Should().BeTrue(); + result.Found.Should().BeTrue(); + result.TermVectors.Count().Should().Be(1); + + var contentTermVector = result.TermVectors["content"]; + contentTermVector.FieldStatistics.Should().BeNull(); + } + + [Test] + public void TermVectorNonMappedFieldTest() + { + var result = _client.TermVector(s => s + .Id("1") + .Fields(ep => ep.Name)); + + result.IsValid.Should().BeTrue(); + result.TermVectors.Count().ShouldBeEquivalentTo(0); + } + + [Test] + public void TermVectorNonExistentIdTest() + { + var result = _client.TermVector(s => s + .Id("thisiddoesnotexist") + .Fields(ep => ep.Name)); + + result.IsValid.Should().Be(true); + result.Found.Should().Be(false); + result.TermVectors.Count.Should().Be(0); + } + } +} diff --git a/src/Tests/Nest.Tests.Integration/IntegrationSetup.cs b/src/Tests/Nest.Tests.Integration/IntegrationSetup.cs index 6424a5bc897..a3d8bad843d 100644 --- a/src/Tests/Nest.Tests.Integration/IntegrationSetup.cs +++ b/src/Tests/Nest.Tests.Integration/IntegrationSetup.cs @@ -24,7 +24,10 @@ public static void Setup() var createIndexResult = client.CreateIndex(ElasticsearchConfiguration.DefaultIndex, c => c .NumberOfReplicas(0) .NumberOfShards(1) - .AddMapping(m => m.MapFromAttributes()) + .AddMapping(m => m + .MapFromAttributes() + .Properties(p => p + .String(s => s.Name(ep => ep.Content).TermVector(TermVectorOption.with_positions_offsets_payloads)))) .AddMapping(m => m.MapFromAttributes()) .AddMapping(m => m.Properties(pp=>pp .String(sm => sm.Name(p => p.Name1).Index(FieldIndexOption.not_analyzed)) @@ -35,7 +38,10 @@ public static void Setup() var createAntotherIndexResult = client.CreateIndex(ElasticsearchConfiguration.DefaultIndex + "_clone", c => c .NumberOfReplicas(0) .NumberOfShards(1) - .AddMapping(m => m.MapFromAttributes()) + .AddMapping(m => m + .MapFromAttributes() + .Properties(p => p + .String(s => s.Name(ep => ep.Content).TermVector(TermVectorOption.with_positions_offsets_payloads)))) .AddMapping(m => m.MapFromAttributes()) .AddMapping(m => m.Properties(pp => pp .String(sm => sm.Name(p => p.Name1).Index(FieldIndexOption.not_analyzed)) @@ -54,8 +60,8 @@ public static void Setup() [TearDown] public static void TearDown() { - var client = ElasticsearchConfiguration.Client; - client.DeleteIndex(di=>di.Indices(ElasticsearchConfiguration.DefaultIndex, ElasticsearchConfiguration.DefaultIndex + "_*")); + var client = ElasticsearchConfiguration.Client; + client.DeleteIndex(di => di.Indices(ElasticsearchConfiguration.DefaultIndex, ElasticsearchConfiguration.DefaultIndex + "_*")); } } } diff --git a/src/Tests/Nest.Tests.Integration/Nest.Tests.Integration.csproj b/src/Tests/Nest.Tests.Integration/Nest.Tests.Integration.csproj index c8d38168484..6e4e2ce05d6 100644 --- a/src/Tests/Nest.Tests.Integration/Nest.Tests.Integration.csproj +++ b/src/Tests/Nest.Tests.Integration/Nest.Tests.Integration.csproj @@ -105,6 +105,8 @@ + +