Skip to content

Commit 753766d

Browse files
authored
Merge branch '2.x' into fix/2.x-similarities
2 parents 31e03c8 + efbb717 commit 753766d

File tree

6 files changed

+182
-101
lines changed

6 files changed

+182
-101
lines changed

docs/search/request/highlighting-usage.asciidoc

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ s => s
3737
.Highlight(h => h
3838
.PreTags("<tag1>")
3939
.PostTags("</tag1>")
40+
.Encoder("html")
4041
.Fields(
4142
fs => fs
4243
.Field(p => p.Name.Suffix("standard"))
@@ -48,30 +49,28 @@ s => s
4849
fs => fs
4950
.Field(p => p.LeadDeveloper.FirstName)
5051
.Type(HighlighterType.Fvh)
51-
.BoundaryMaxScan(50)
5252
.PreTags("<name>")
5353
.PostTags("</name>")
54+
.BoundaryMaxScan(50)
55+
.PhraseLimit(10)
5456
.HighlightQuery(q => q
5557
.Match(m => m
5658
.Field(p => p.LeadDeveloper.FirstName)
5759
.Query("Kurt Edgardo Naomi Dariana Justice Felton")
5860
)
5961
),
6062
fs => fs
61-
.Field(p => p.State.Suffix("offsets"))
63+
.Field(p => p.LeadDeveloper.LastName)
6264
.Type(HighlighterType.Postings)
63-
.PreTags("<state>")
64-
.PostTags("</state>")
65+
.PreTags("<name>")
66+
.PostTags("</name>")
6567
.HighlightQuery(q => q
66-
.Terms(t => t
67-
.Field(f => f.State.Suffix("offsets"))
68-
.Terms(
69-
StateOfBeing.Stable.ToString().ToLowerInvariant(),
70-
StateOfBeing.BellyUp.ToString().ToLowerInvariant()
68+
.Match(m => m
69+
.Field(p => p.LeadDeveloper.LastName)
70+
.Query(LastNameSearch)
7171
)
7272
)
7373
)
74-
)
7574
)
7675
----
7776

@@ -91,6 +90,7 @@ new SearchRequest<Project>
9190
{
9291
PreTags = new[] { "<tag1>" },
9392
PostTags = new[] { "</tag1>" },
93+
Encoder = "html",
9494
Fields = new Dictionary<Field, IHighlightField>
9595
{
9696
{ "name.standard", new HighlightField
@@ -104,7 +104,8 @@ new SearchRequest<Project>
104104
},
105105
{ "leadDeveloper.firstName", new HighlightField
106106
{
107-
CustomType = "fvh",
107+
CustomType = "fvh", <1>
108+
PhraseLimit = 10,
108109
BoundaryMaxScan = 50,
109110
PreTags = new[] { "<name>"},
110111
PostTags = new[] { "</name>"},
@@ -115,22 +116,23 @@ new SearchRequest<Project>
115116
}
116117
}
117118
},
118-
{ "state.offsets", new HighlightField
119+
{ "leadDeveloper.lastName", new HighlightField
119120
{
120121
Type = HighlighterType.Postings,
121-
PreTags = new[] { "<state>"},
122-
PostTags = new[] { "</state>"},
123-
HighlightQuery = new TermsQuery
122+
PreTags = new[] { "<name>"},
123+
PostTags = new[] { "</name>"},
124+
HighlightQuery = new MatchQuery
124125
{
125-
Field = "state.offsets",
126-
Terms = new [] { "stable", "bellyup" }
126+
Field = "leadDeveloper.lastName",
127+
Query = LastNameSearch
127128
}
128129
}
129130
}
130131
}
131132
}
132133
}
133134
----
135+
<1> `CustomType` can be used to define a custom highlighter
134136

135137
[source,javascript]
136138
.Example json output
@@ -150,6 +152,7 @@ new SearchRequest<Project>
150152
"post_tags": [
151153
"</tag1>"
152154
],
155+
"encoder": "html",
153156
"fields": {
154157
"name.standard": {
155158
"type": "plain",
@@ -160,6 +163,7 @@ new SearchRequest<Project>
160163
},
161164
"leadDeveloper.firstName": {
162165
"type": "fvh",
166+
"phrase_limit": 10,
163167
"boundary_max_scan": 50,
164168
"pre_tags": [
165169
"<name>"
@@ -175,20 +179,19 @@ new SearchRequest<Project>
175179
}
176180
}
177181
},
178-
"state.offsets": {
182+
"leadDeveloper.lastName": {
179183
"type": "postings",
180184
"pre_tags": [
181-
"<state>"
185+
"<name>"
182186
],
183187
"post_tags": [
184-
"</state>"
188+
"</name>"
185189
],
186190
"highlight_query": {
187-
"terms": {
188-
"state.offsets": [
189-
"stable",
190-
"bellyup"
191-
]
191+
"match": {
192+
"leadDeveloper.lastName": {
193+
"query": "Stokes"
194+
}
192195
}
193196
}
194197
}
@@ -224,12 +227,12 @@ foreach (var highlightsByDocumentId in response.Highlights)
224227
highlight.Should().Contain("</name>");
225228
}
226229
}
227-
else if (highlightHit.Key == "state.offsets")
230+
else if (highlightHit.Key == "leadDeveloper.lastName")
228231
{
229232
foreach (var highlight in highlightHit.Value.Highlights)
230233
{
231-
highlight.Should().Contain("<state>");
232-
highlight.Should().Contain("</state>");
234+
highlight.Should().Contain("<name>");
235+
highlight.Should().Contain("</name>");
233236
}
234237
}
235238
else

src/Nest/Aggregations/Bucket/SignificantTerms/SignificantTermsAggregation.cs

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,26 @@ public interface ISignificantTermsAggregation : IBucketAggregation
3434
/// Return only terms that match equal to or more than a configurable
3535
/// number of hits
3636
/// </summary>
37-
[JsonProperty("min_doc_count")]
37+
[JsonIgnore]
38+
[Obsolete("Use MinimumDocumentCountAsLong. Fixed in NEST 6.x")]
3839
int? MinimumDocumentCount { get; set; }
3940

41+
/// <summary>
42+
/// Return only terms that match equal to or more than a configurable
43+
/// number of hits
44+
/// </summary>
45+
[JsonProperty("min_doc_count")]
46+
long? MinimumDocumentCountAsLong { get; set; }
47+
48+
/// <summary>
49+
/// Regulates the certainty a shard has if the term should actually be added to the candidate
50+
/// list or not with respect to the <see cref="MinimumDocumentCountAsLong"/>.
51+
/// Terms will only be considered if their local shard frequency within
52+
/// the set is higher than the <see cref="ShardMinimumDocumentCount"/>.
53+
/// </summary>
54+
[JsonProperty("shard_min_doc_count")]
55+
long? ShardMinimumDocumentCount { get; set; }
56+
4057
/// <summary>
4158
/// Determines the mechanism by which aggregations are executed
4259
/// </summary>
@@ -103,7 +120,6 @@ public interface ISignificantTermsAggregation : IBucketAggregation
103120
/// </summary>
104121
[JsonProperty("background_filter")]
105122
QueryContainer BackgroundFilter { get; set; }
106-
107123
}
108124

109125
public class SignificantTermsAggregation : BucketAggregationBase, ISignificantTermsAggregation
@@ -114,8 +130,19 @@ public class SignificantTermsAggregation : BucketAggregationBase, ISignificantTe
114130
public int? Size { get; set; }
115131
/// <inheritdoc />
116132
public int? ShardSize { get; set; }
133+
134+
[Obsolete("Use MinimumDocumentCountAsLong. Fixed in NEST 6.x")]
135+
/// <inheritdoc />
136+
public int? MinimumDocumentCount
137+
{
138+
get => MinimumDocumentCountAsLong > int.MaxValue ? int.MaxValue : (int?)MinimumDocumentCountAsLong;
139+
set => MinimumDocumentCountAsLong = value;
140+
}
141+
117142
/// <inheritdoc />
118-
public int? MinimumDocumentCount { get; set; }
143+
public long? MinimumDocumentCountAsLong { get; set; }
144+
/// <inheritdoc />
145+
public long? ShardMinimumDocumentCount { get; set; }
119146
/// <inheritdoc />
120147
public TermsAggregationExecutionHint? ExecutionHint { get; set; }
121148

@@ -161,7 +188,16 @@ public class SignificantTermsAggregationDescriptor<T>
161188

162189
int? ISignificantTermsAggregation.ShardSize { get; set; }
163190

164-
int? ISignificantTermsAggregation.MinimumDocumentCount { get; set; }
191+
[Obsolete("Use MinimumDocumentCountAsLong. Fixed in NEST 6.x")]
192+
int? ISignificantTermsAggregation.MinimumDocumentCount
193+
{
194+
get => Self.MinimumDocumentCountAsLong > int.MaxValue ? int.MaxValue : (int?)Self.MinimumDocumentCountAsLong;
195+
set => Self.MinimumDocumentCountAsLong = value;
196+
}
197+
198+
long? ISignificantTermsAggregation.MinimumDocumentCountAsLong { get; set; }
199+
200+
long? ISignificantTermsAggregation.ShardMinimumDocumentCount { get; set; }
165201

166202
TermsAggregationExecutionHint? ISignificantTermsAggregation.ExecutionHint { get; set; }
167203

@@ -225,10 +261,19 @@ public SignificantTermsAggregationDescriptor<T> Exclude(Func<FluentDictionary<st
225261
/// <inheritdoc />
226262
public SignificantTermsAggregationDescriptor<T> ShardSize(int shardSize) => Assign(a => a.ShardSize = shardSize);
227263

264+
[Obsolete("Use MinimumDocumentCountAsLong. Fixed in NEST 6.x")]
228265
/// <inheritdoc />
229266
public SignificantTermsAggregationDescriptor<T> MinimumDocumentCount(int minimumDocumentCount) =>
230267
Assign(a => a.MinimumDocumentCount = minimumDocumentCount);
231268

269+
/// <inheritdoc />
270+
public SignificantTermsAggregationDescriptor<T> MinimumDocumentCountAsLong(long minimumDocumentCount) =>
271+
Assign(a => a.MinimumDocumentCountAsLong = minimumDocumentCount);
272+
273+
/// <inheritdoc />
274+
public SignificantTermsAggregationDescriptor<T> ShardMinimumDocumentCount(long shardMinimumDocumentCount) =>
275+
Assign(a => a.ShardMinimumDocumentCount = shardMinimumDocumentCount);
276+
232277
/// <inheritdoc />
233278
public SignificantTermsAggregationDescriptor<T> MutualInformation(Func<MutualInformationHeuristicDescriptor, IMutualInformationHeuristic> mutualInformationSelector = null) =>
234279
Assign(a => a.MutualInformation = mutualInformationSelector.InvokeOrDefault(new MutualInformationHeuristicDescriptor()));

0 commit comments

Comments
 (0)