diff --git a/src/Elasticsearch.Net/Domain/Enums.Generated.cs b/src/Elasticsearch.Net/Domain/Enums.Generated.cs index cfb9961a827..7e9a07a3f55 100644 --- a/src/Elasticsearch.Net/Domain/Enums.Generated.cs +++ b/src/Elasticsearch.Net/Domain/Enums.Generated.cs @@ -7,7 +7,7 @@ ///This file contains all the typed enums that the client rest api spec exposes. ///This file is automatically generated from https://github.com/elasticsearch/elasticsearch-rest-api-spec -///Generated of commit 5f64a7f7e8 +///Generated of commit namespace Elasticsearch.Net { diff --git a/src/Elasticsearch.Net/Domain/RequestParameters.Generated.cs b/src/Elasticsearch.Net/Domain/RequestParameters.Generated.cs index 8bb29c069ba..7b6e6739e66 100644 --- a/src/Elasticsearch.Net/Domain/RequestParameters.Generated.cs +++ b/src/Elasticsearch.Net/Domain/RequestParameters.Generated.cs @@ -7,7 +7,7 @@ ///This file contains all the typed querystring parameters that are generated of the client spec. ///This file is automatically generated from https://github.com/elasticsearch/elasticsearch-rest-api-spec -///Generated of commit 5f64a7f7e8 +///Generated of commit namespace Elasticsearch.Net { diff --git a/src/Elasticsearch.Net/IElasticsearchClient.Generated.cs b/src/Elasticsearch.Net/IElasticsearchClient.Generated.cs index 09f7d4bf10b..aafb9362ee8 100644 --- a/src/Elasticsearch.Net/IElasticsearchClient.Generated.cs +++ b/src/Elasticsearch.Net/IElasticsearchClient.Generated.cs @@ -15,7 +15,7 @@ namespace Elasticsearch.Net ///This file is automatically generated from https://github.com/elasticsearch/elasticsearch-rest-api-spec /// ///
-	///Generated of commit 5f64a7f7e8
+	///Generated of commit 
 	///
/// public interface IElasticsearchClient 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/TermVectorDescriptor.cs b/src/Nest/DSL/TermVectorDescriptor.cs new file mode 100644 index 00000000000..4d39fcd3fa1 --- /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, TermvectorRequestParameters> + , 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 bf07491644b..6449c4e2b1f 100644 --- a/src/Nest/DSL/_Descriptors.generated.cs +++ b/src/Nest/DSL/_Descriptors.generated.cs @@ -6,7 +6,7 @@ using Elasticsearch.Net; ///This file lays the base for all the descriptors based on the query string parameters in the spec for IElasticClient. ///This file is automatically generated from https://github.com/elasticsearch/elasticsearch-rest-api-spec -///Generated of commit 5f64a7f7e8 +///Generated of commit namespace Nest { @@ -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; @@ -4981,13 +4981,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 TermvectorRequestParameters _QueryString = new TermvectorRequestParameters(); ///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; @@ -4995,7 +4995,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; @@ -5003,7 +5003,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; @@ -5011,7 +5011,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; @@ -5022,7 +5022,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; @@ -5030,7 +5030,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; @@ -5038,7 +5038,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; @@ -5046,7 +5046,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; @@ -5054,7 +5054,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; @@ -5062,7 +5062,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/RequestParametersExtensions.Generated.cs b/src/Nest/Domain/RequestParametersExtensions.Generated.cs index 2f1a6dc6442..2941bfb43df 100644 --- a/src/Nest/Domain/RequestParametersExtensions.Generated.cs +++ b/src/Nest/Domain/RequestParametersExtensions.Generated.cs @@ -9,7 +9,7 @@ ///This file contains all the typed request parameters that are generated of the client spec. ///This file is automatically generated from https://github.com/elasticsearch/elasticsearch-rest-api-spec -///Generated of commit 5f64a7f7e8 +///Generated of commit namespace Nest { diff --git a/src/Nest/Domain/Responses/MultiTermVectorResponse.cs b/src/Nest/Domain/Responses/MultiTermVectorResponse.cs new file mode 100644 index 00000000000..3f8de58ee4d --- /dev/null +++ b/src/Nest/Domain/Responses/MultiTermVectorResponse.cs @@ -0,0 +1,26 @@ +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; + Documents = new List(); + } + + [JsonProperty("docs")] + public IEnumerable Documents { get; internal set; } + } +} diff --git a/src/Nest/Domain/Responses/TermVectorResponse.cs b/src/Nest/Domain/Responses/TermVectorResponse.cs new file mode 100644 index 00000000000..1e7c1850f08 --- /dev/null +++ b/src/Nest/Domain/Responses/TermVectorResponse.cs @@ -0,0 +1,30 @@ +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; + TermVectors = new Dictionary(); + } + + [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..90b66472933 --- /dev/null +++ b/src/Nest/Domain/TermVector/TermVector.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Newtonsoft.Json; + +namespace Nest +{ + [JsonObject] + public class TermVector + { + public TermVector() + { + Terms = new Dictionary(); + } + + [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..d05d88b1ebe --- /dev/null +++ b/src/Nest/Domain/TermVector/TermVectorTerm.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Newtonsoft.Json; + +namespace Nest +{ + [JsonObject] + public class TermVectorTerm + { + public TermVectorTerm() + { + Tokens = new List(); + } + + [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-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/ElasticClient-TermVector.cs b/src/Nest/ElasticClient-TermVector.cs new file mode 100644 index 00000000000..29eb54033a2 --- /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, TermvectorRequestParameters, TermVectorResponse>( + termVectorSelector, + (p, d) => this.RawDispatch.TermvectorDispatch(p, d) + ); + } + + public Task TermVectorAsync(Func, TermvectorDescriptor> termVectorSelector) + where T : class + { + return this.DispatchAsync, TermvectorRequestParameters, 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 1b3e302720f..d964d99cb35 100644 --- a/src/Nest/IElasticClient.cs +++ b/src/Nest/IElasticClient.cs @@ -1034,6 +1034,44 @@ 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; + + /// + /// 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. /// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-status.html @@ -1185,6 +1223,6 @@ Task DocumentExistsAsync(Func, D /// The repository name that holds our snapshot /// The name of the snapshot that we want to restore /// Optionally further describe the restore operation - Task RestoreAsync(string repository, string snapshotName, Func selector = null); + Task RestoreAsync(string repository, string snapshotName, Func selector = null); } -} \ No newline at end of file +} diff --git a/src/Nest/Nest.csproj b/src/Nest/Nest.csproj index d28c0dbaa67..27acbf536ea 100644 --- a/src/Nest/Nest.csproj +++ b/src/Nest/Nest.csproj @@ -134,10 +134,12 @@ + + @@ -155,6 +157,11 @@ + + + + + @@ -226,6 +233,7 @@ + @@ -247,11 +255,13 @@ + + 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 @@ + +