Skip to content

Commit a47c490

Browse files
committed
Fix Highlighting usage integration test
Test used Unified highlighter, which is not available in Elasticsearch <5.3.0. There is a separate test for this.
1 parent 4cd96a3 commit a47c490

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

docs/search/request/highlighting-usage.asciidoc

Lines changed: 6 additions & 0 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"))
@@ -52,6 +53,7 @@ s => s
5253
.PreTags("<name>")
5354
.PostTags("</name>")
5455
.BoundaryMaxScan(50)
56+
.PhraseLimit(10)
5557
.HighlightQuery(q => q
5658
.Match(m => m
5759
.Field(p => p.LeadDeveloper.FirstName)
@@ -92,6 +94,7 @@ new SearchRequest<Project>
9294
{
9395
PreTags = new[] { "<tag1>" },
9496
PostTags = new[] { "</tag1>" },
97+
Encoder = "html",
9598
Fields = new Dictionary<Field, IHighlightField>
9699
{
97100
{ "name.standard", new HighlightField
@@ -107,6 +110,7 @@ new SearchRequest<Project>
107110
{ "leadDeveloper.firstName", new HighlightField
108111
{
109112
Type = "fvh",
113+
PhraseLimit = 10,
110114
BoundaryMaxScan = 50,
111115
PreTags = new[] { "<name>"},
112116
PostTags = new[] { "</name>"},
@@ -152,6 +156,7 @@ new SearchRequest<Project>
152156
"post_tags": [
153157
"</tag1>"
154158
],
159+
"encoder": "html",
155160
"fields": {
156161
"name.standard": {
157162
"type": "plain",
@@ -163,6 +168,7 @@ new SearchRequest<Project>
163168
},
164169
"leadDeveloper.firstName": {
165170
"type": "fvh",
171+
"phrase_limit": 10,
166172
"boundary_max_scan": 50,
167173
"pre_tags": [
168174
"<name>"

src/Tests/Search/Request/HighlightingUsageTests.cs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class HighlightingUsageTests : SearchUsageTestBase
2323
{
2424
public HighlightingUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
2525

26-
public string LastNameSearch { get; } = Project.First.LeadDeveloper.LastName;
26+
public string LastNameSearch { get; } = Project.Instance.LeadDeveloper.LastName;
2727

2828
protected override object ExpectJson => new
2929
{
@@ -77,20 +77,16 @@ public HighlightingUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : ba
7777
}
7878
}
7979
},
80-
{ "leadDeveloper.lastName", new Dictionary<string, object>
80+
{ "state.offsets", new Dictionary<string, object>
8181
{
82-
{ "type", "unified" },
83-
{ "pre_tags", new [] { "<name>" } },
84-
{ "post_tags", new [] { "</name>" } },
82+
{ "type", "postings" },
83+
{ "pre_tags", new [] { "<state>" } },
84+
{ "post_tags", new [] { "</state>" } },
8585
{ "highlight_query", new Dictionary<string, object>
8686
{
87-
{ "match", new Dictionary<string, object>
87+
{ "terms", new Dictionary<string, object>
8888
{
89-
{ "leadDeveloper.lastName", new Dictionary<string, object>
90-
{
91-
{ "query", LastNameSearch }
92-
}
93-
}
89+
{ "state.offsets", new [] { "stable" , "bellyup" } }
9490
}
9591
}
9692
}
@@ -135,14 +131,17 @@ public HighlightingUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : ba
135131
)
136132
),
137133
fs => fs
138-
.Field(p => p.LeadDeveloper.LastName)
139-
.Type(HighlighterType.Unified)
140-
.PreTags("<name>")
141-
.PostTags("</name>")
134+
.Field(p => p.State.Suffix("offsets"))
135+
.Type(HighlighterType.Postings)
136+
.PreTags("<state>")
137+
.PostTags("</state>")
142138
.HighlightQuery(q => q
143-
.Match(m => m
144-
.Field(p => p.LeadDeveloper.LastName)
145-
.Query(LastNameSearch)
139+
.Terms(t => t
140+
.Field(f => f.State.Suffix("offsets"))
141+
.Terms(
142+
StateOfBeing.Stable.ToString().ToLowerInvariant(),
143+
StateOfBeing.BellyUp.ToString().ToLowerInvariant()
144+
)
146145
)
147146
)
148147
)
@@ -187,15 +186,15 @@ public HighlightingUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : ba
187186
}
188187
}
189188
},
190-
{ "leadDeveloper.lastName", new HighlightField
189+
{ "state.offsets", new HighlightField
191190
{
192-
Type = HighlighterType.Unified,
193-
PreTags = new[] { "<name>"},
194-
PostTags = new[] { "</name>"},
195-
HighlightQuery = new MatchQuery
191+
Type = HighlighterType.Postings,
192+
PreTags = new[] { "<state>"},
193+
PostTags = new[] { "</state>"},
194+
HighlightQuery = new TermsQuery
196195
{
197-
Field = "leadDeveloper.lastName",
198-
Query = LastNameSearch
196+
Field = "state.offsets",
197+
Terms = new [] { "stable", "bellyup" }
199198
}
200199
}
201200
}

0 commit comments

Comments
 (0)