Skip to content

Commit fd9fd8d

Browse files
committed
Merge branch 'master' of github.com:elastic/elasticsearch-net
2 parents e6323c7 + cadfc40 commit fd9fd8d

File tree

2 files changed

+83
-30
lines changed

2 files changed

+83
-30
lines changed

src/Nest/Indices/Analyze/AnalyzeRequest.cs

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public partial interface IAnalyzeRequest
1111
{
1212
///<summary>The name of the analyzer to use</summary>
1313
[JsonProperty("analyzer")]
14-
Union<string, IAnalyzer> Analyzer { get; set; }
14+
string Analyzer { get; set; }
1515

1616
///<summary>The name of the normalizer to use</summary>
1717
[JsonProperty("normalizer")]
@@ -58,41 +58,40 @@ public AnalyzeRequest(IndexName indices, string textToAnalyze)
5858
public Union<string, ITokenizer> Tokenizer { get; set; }
5959

6060
/// <inheritdoc />
61-
public bool? Explain { get; set; }
61+
public string Analyzer { get; set; }
6262

6363
/// <inheritdoc />
64-
public IEnumerable<string> Attributes { get; set; }
64+
public bool? Explain { get; set; }
6565

6666
/// <inheritdoc />
67-
public Union<string, IAnalyzer> Analyzer { get; set; }
67+
public IEnumerable<string> Attributes { get; set; }
6868

6969
/// <inheritdoc />
7070
public AnalyzeCharFilters CharFilter { get; set; }
7171

72-
/// <inheritdoc />
73-
public string Normalizer { get; set; }
74-
7572
/// <inheritdoc />
7673
public AnalyzeTokenFilters Filter { get; set; }
7774

75+
/// <inheritdoc />
76+
public string Normalizer { get; set; }
77+
7878
/// <inheritdoc />
7979
public Field Field { get; set; }
8080

8181
/// <inheritdoc />
8282
public IEnumerable<string> Text { get; set; }
83-
8483
}
8584

8685
[DescriptorFor("IndicesAnalyze")]
8786
public partial class AnalyzeDescriptor
8887
{
89-
Union<string, ITokenizer> IAnalyzeRequest.Tokenizer { get; set; }
90-
Union<string, IAnalyzer> IAnalyzeRequest.Analyzer { get; set; }
88+
string IAnalyzeRequest.Analyzer { get; set; }
9189
AnalyzeCharFilters IAnalyzeRequest.CharFilter { get; set; }
92-
string IAnalyzeRequest.Normalizer { get; set; }
9390
AnalyzeTokenFilters IAnalyzeRequest.Filter { get; set; }
91+
string IAnalyzeRequest.Normalizer { get; set; }
9492
Field IAnalyzeRequest.Field { get; set; }
9593
IEnumerable<string> IAnalyzeRequest.Text { get; set; }
94+
Union<string, ITokenizer> IAnalyzeRequest.Tokenizer { get; set; }
9695
bool? IAnalyzeRequest.Explain { get; set; }
9796
IEnumerable<string> IAnalyzeRequest.Attributes { get; set; }
9897

@@ -110,23 +109,12 @@ public AnalyzeDescriptor Tokenizer(Func<AnalyzeTokenizersSelector, ITokenizer> t
110109
///<summary>The name of the analyzer to use</summary>
111110
public AnalyzeDescriptor Analyzer(string analyser) => Assign(a => a.Analyzer = analyser);
112111

113-
///<summary>An inline definition of an analyzer</summary>
114-
public AnalyzeDescriptor Analyzer(Func<AnalyzersDescriptor, IAnalyzer> analyzer) =>
115-
Assign(a =>
116-
{
117-
var v = analyzer?.Invoke(new AnalyzersDescriptor());
118-
if (v != null) a.Analyzer = new Union<string, IAnalyzer>(v);
119-
});
120-
121112
///<summary>A collection of character filters to use for the analysis</summary>
122113
public AnalyzeDescriptor CharFilter(params string[] charFilter) => Assign(a => a.CharFilter = charFilter);
123114

124115
///<summary>A collection of character filters to use for the analysis</summary>
125116
public AnalyzeDescriptor CharFilter(IEnumerable<string> charFilter) => Assign(a => a.CharFilter = charFilter.ToArray());
126117

127-
///<summary>The name of the normalizer to use</summary>
128-
public AnalyzeDescriptor Normalizer(string normalizer) => Assign(a => a.Normalizer = normalizer);
129-
130118
///<summary>A collection of character filters to use for the analysis</summary>
131119
public AnalyzeDescriptor CharFilter(Func<AnalyzeCharFiltersDescriptor, IPromise<AnalyzeCharFilters>> charFilters) =>
132120
Assign(a => a.CharFilter = charFilters?.Invoke(new AnalyzeCharFiltersDescriptor())?.Value);
@@ -141,6 +129,9 @@ public AnalyzeDescriptor CharFilter(Func<AnalyzeCharFiltersDescriptor, IPromise<
141129
public AnalyzeDescriptor Filter(Func<AnalyzeTokenFiltersDescriptor, IPromise<AnalyzeTokenFilters>> tokenFilters) =>
142130
Assign(a => a.Filter = tokenFilters?.Invoke(new AnalyzeTokenFiltersDescriptor())?.Value);
143131

132+
///<summary>The name of the normalizer to use</summary>
133+
public AnalyzeDescriptor Normalizer(string normalizer) => Assign(a => a.Normalizer = normalizer);
134+
144135
///<summary>Use the analyzer configured for this field (instead of passing the analyzer name)</summary>
145136
public AnalyzeDescriptor Field(Field field) => Assign(a => a.Field = field);
146137

@@ -153,13 +144,13 @@ public AnalyzeDescriptor Filter(Func<AnalyzeTokenFiltersDescriptor, IPromise<Ana
153144
///<summary>The text on which the analysis should be performed</summary>
154145
public AnalyzeDescriptor Text(IEnumerable<string> text) => Assign(a => a.Text = text);
155146

156-
/// <inheritdoc cref="IAnalyzeRequst.Explain" />
157-
public AnalyzeDescriptor Explain(bool? explain = true) => Assign(a => a.Explain = explain);
147+
///<summary>Return more details, and output the analyzer chain per step in the process</summary>
148+
public AnalyzeDescriptor Explain(bool explain = true) => Assign(a => a.Explain = explain);
158149

159-
/// <inheritdoc cref="IAnalyzeRequst.Attributes" />
150+
///<summary>Filter only certain token attributes to be returned</summary>
160151
public AnalyzeDescriptor Attributes(params string[] attributes) => Assign(a => a.Attributes = attributes);
161152

162-
/// <inheritdoc cref="IAnalyzeRequst.Attributes" />
163-
public AnalyzeDescriptor Attributes(IEnumerable<string> attributes) => Assign(a => a.Attributes = attributes);
153+
///<summary>Filter only certain token attributes to be returned</summary>
154+
public AnalyzeDescriptor Attributes(IEnumerable<string> attributes) => Assign(a => a.Attributes = attributes.ToArray());
164155
}
165156
}

src/Tests/Indices/Analyze/AnalyzeApiTests.cs

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ protected override LazyResponses ClientUsage() => Calls(
4848
};
4949
}
5050

51-
public class AnalyzeInlineApiTests : ApiIntegrationTestBase<ReadOnlyCluster, IAnalyzeResponse, IAnalyzeRequest, AnalyzeDescriptor, AnalyzeRequest>
51+
public class AnalyzeInlineAnalyzerApiTests : ApiIntegrationTestBase<ReadOnlyCluster, IAnalyzeResponse, IAnalyzeRequest, AnalyzeDescriptor, AnalyzeRequest>
5252
{
5353
protected const string TextToAnalyze = "F# is <b>THE SUPERIOR</b> language :) :gandalf: ";
5454

55-
public AnalyzeInlineApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
55+
public AnalyzeInlineAnalyzerApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
56+
5657
protected override LazyResponses ClientUsage() => Calls(
5758
fluent: (client, f) => client.Analyze(f),
5859
fluentAsync: (client, f) => client.AnalyzeAsync(f),
@@ -118,7 +119,68 @@ protected override void ExpectResponse(IAnalyzeResponse response)
118119
}
119120
}
120121

121-
public class AnalyzeExplainApiTests : AnalyzeInlineApiTests
122+
public class AnalyzeInlineNormalizerApiTests : ApiIntegrationTestBase<ReadOnlyCluster, IAnalyzeResponse, IAnalyzeRequest, AnalyzeDescriptor, AnalyzeRequest>
123+
{
124+
private const string TextToAnalyze = "F# is <b>THE SUPERIOR</b> language :) :gandalf: ";
125+
126+
public AnalyzeInlineNormalizerApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
127+
128+
protected override LazyResponses ClientUsage() => Calls(
129+
fluent: (client, f) => client.Analyze(f),
130+
fluentAsync: (client, f) => client.AnalyzeAsync(f),
131+
request: (client, r) => client.Analyze(r),
132+
requestAsync: (client, r) => client.AnalyzeAsync(r)
133+
);
134+
135+
protected override bool ExpectIsValid => true;
136+
protected override int ExpectStatusCode => 200;
137+
protected override HttpMethod HttpMethod => HttpMethod.POST;
138+
protected override string UrlPath => $"/_analyze";
139+
140+
protected override object ExpectJson => new
141+
{
142+
text = new[] { TextToAnalyze },
143+
char_filter = new object[]
144+
{
145+
new { type = "mapping", mappings = new[] { "F# => fsharp" } }
146+
},
147+
filter = new object[]
148+
{
149+
"lowercase"
150+
}
151+
};
152+
153+
protected override Func<AnalyzeDescriptor, IAnalyzeRequest> Fluent => d => d
154+
.Text(TextToAnalyze)
155+
.CharFilter(c => c
156+
.Mapping(m => m.Mappings("F# => fsharp"))
157+
)
158+
.Filter(t => t
159+
.Name("lowercase")
160+
);
161+
162+
protected override AnalyzeRequest Initializer => new AnalyzeRequest
163+
{
164+
Text = new[] { TextToAnalyze },
165+
CharFilter = new AnalyzeCharFilters
166+
{
167+
new MappingCharFilter { Mappings = new[] { "F# => fsharp"}}
168+
},
169+
Filter = new AnalyzeTokenFilters
170+
{
171+
"lowercase"
172+
}
173+
};
174+
175+
protected override void ExpectResponse(IAnalyzeResponse response)
176+
{
177+
response.Tokens.Should().HaveCount(1);
178+
var token = response.Tokens.Single().Token;
179+
token.Should().Be("fsharp is <b>the superior</b> language :) :gandalf: ");
180+
}
181+
}
182+
183+
public class AnalyzeExplainApiTests : AnalyzeInlineAnalyzerApiTests
122184
{
123185
public AnalyzeExplainApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
124186

0 commit comments

Comments
 (0)