-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add phrase_limit to highlighting #2959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8adfa8a
4809caf
95782d3
8ba4974
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,17 +68,10 @@ public interface IHighlightField | |
int? BoundaryMaxScan { get; set; } | ||
|
||
/// <summary> | ||
/// Define how highlighted text will be encoded. | ||
/// It can be either default (no encoding) or html (will escape html, if you use html highlighting tags). | ||
/// </summary> | ||
[JsonProperty("encoder")] | ||
string Encoder { get; set; } | ||
|
||
/// <summary> | ||
/// The order in which highlighted fragments are sorted | ||
/// The order in which highlighted fragments are sorted. Only valid for the unified highlighter. | ||
/// </summary> | ||
[JsonProperty("order")] | ||
string Order { get; set; } | ||
HighlighterOrder? Order { get; set; } | ||
|
||
/// <summary> | ||
/// Use a specific "tag" schemas. | ||
|
@@ -91,7 +84,7 @@ public interface IHighlightField | |
/// <em class="hlt10"> | ||
/// </remarks> | ||
[JsonProperty("tags_schema")] | ||
string TagsSchema { get; set; } | ||
HighlighterTagsSchema? TagsSchema { get; set; } | ||
|
||
/// <summary> | ||
/// Determines if only fields that hold a query match will be highlighted. Set to <c>false</c> | ||
|
@@ -129,6 +122,7 @@ public interface IHighlightField | |
/// </summary> | ||
[JsonProperty("fragmenter")] | ||
HighlighterFragmenter? Fragmenter { get; set; } | ||
|
||
/// <summary> | ||
/// The type of highlighter to use. Can be a defined or custom highlighter | ||
/// </summary> | ||
|
@@ -155,6 +149,15 @@ public interface IHighlightField | |
/// </summary> | ||
[JsonProperty("highlight_query")] | ||
QueryContainer HighlightQuery { get; set; } | ||
|
||
/// <summary> | ||
/// Controls the number of matching phrases in a document that are considered. Prevents the | ||
/// <see cref="HighlighterType.Fvh"/> highlighter from analyzing too many phrases and consuming too much memory. | ||
/// When using matched_fields, <see cref="PhraseLimit"/> phrases per matched field are considered. Raising the limit increases query time | ||
/// and consumes more memory. Only supported by the <see cref="HighlighterType.Fvh"/> highlighter. Defaults to 256. | ||
/// </summary> | ||
[JsonProperty("phrase_limit")] | ||
int? PhraseLimit { get; set; } | ||
} | ||
|
||
public class HighlightField : IHighlightField | ||
|
@@ -176,11 +179,9 @@ public class HighlightField : IHighlightField | |
/// <inheritdoc/> | ||
public int? BoundaryMaxScan { get; set; } | ||
/// <inheritdoc/> | ||
public string Encoder { get; set; } | ||
public HighlighterOrder? Order { get; set; } | ||
/// <inheritdoc/> | ||
public string Order { get; set; } | ||
/// <inheritdoc/> | ||
public string TagsSchema { get; set; } | ||
public HighlighterTagsSchema? TagsSchema { get; set; } | ||
/// <inheritdoc/> | ||
public bool? RequireFieldMatch { get; set; } | ||
/// <inheritdoc/> | ||
|
@@ -201,6 +202,8 @@ public class HighlightField : IHighlightField | |
public Fields MatchedFields { get; set; } | ||
/// <inheritdoc/> | ||
public QueryContainer HighlightQuery { get; set; } | ||
/// <inheritdoc/> | ||
public int? PhraseLimit { get; set; } | ||
} | ||
|
||
public class HighlightFieldDescriptor<T> : DescriptorBase<HighlightFieldDescriptor<T>,IHighlightField>, IHighlightField | ||
|
@@ -214,9 +217,8 @@ public class HighlightFieldDescriptor<T> : DescriptorBase<HighlightFieldDescript | |
int? IHighlightField.NumberOfFragments { get; set; } | ||
int? IHighlightField.FragmentOffset { get; set; } | ||
int? IHighlightField.BoundaryMaxScan { get; set; } | ||
string IHighlightField.Encoder { get; set; } | ||
string IHighlightField.Order { get; set; } | ||
string IHighlightField.TagsSchema { get; set; } | ||
HighlighterOrder? IHighlightField.Order { get; set; } | ||
HighlighterTagsSchema? IHighlightField.TagsSchema { get; set; } | ||
bool? IHighlightField.RequireFieldMatch { get; set; } | ||
string IHighlightField.BoundaryChars { get; set; } | ||
int? IHighlightField.MaxFragmentLength { get; set; } | ||
|
@@ -227,6 +229,7 @@ public class HighlightFieldDescriptor<T> : DescriptorBase<HighlightFieldDescript | |
bool? IHighlightField.ForceSource { get; set; } | ||
Fields IHighlightField.MatchedFields { get; set; } | ||
QueryContainer IHighlightField.HighlightQuery { get; set; } | ||
int? IHighlightField.PhraseLimit { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public HighlightFieldDescriptor<T> Field(Field field) => Assign(a => a.Field = field); | ||
|
@@ -238,7 +241,7 @@ public class HighlightFieldDescriptor<T> : DescriptorBase<HighlightFieldDescript | |
public HighlightFieldDescriptor<T> AllField() => this.Field("_all"); | ||
|
||
/// <inheritdoc/> | ||
public HighlightFieldDescriptor<T> TagsSchema(string schema = "styled") => Assign(a => a.TagsSchema = schema); | ||
public HighlightFieldDescriptor<T> TagsSchema(HighlighterTagsSchema? schema) => Assign(a => a.TagsSchema = schema); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No default? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can make it the default, but the client generally doesn't have default values for nullable enums. I suspect this had a default value more as a hint for the accepted string value. |
||
|
||
/// <inheritdoc/> | ||
public HighlightFieldDescriptor<T> ForceSource(bool? force = true) => Assign(a => a.ForceSource = force); | ||
|
@@ -274,10 +277,7 @@ public class HighlightFieldDescriptor<T> : DescriptorBase<HighlightFieldDescript | |
public HighlightFieldDescriptor<T> FragmentOffset(int? fragmentOffset) => Assign(a => a.FragmentOffset = fragmentOffset); | ||
|
||
/// <inheritdoc/> | ||
public HighlightFieldDescriptor<T> Encoder(string encoder) => Assign(a => a.Encoder = encoder); | ||
|
||
/// <inheritdoc/> | ||
public HighlightFieldDescriptor<T> Order(string order) => Assign(a => a.Order = order); | ||
public HighlightFieldDescriptor<T> Order(HighlighterOrder? order) => Assign(a => a.Order = order); | ||
|
||
/// <inheritdoc/> | ||
public HighlightFieldDescriptor<T> RequireFieldMatch(bool? requireFieldMatch = true) => Assign(a => a.RequireFieldMatch = requireFieldMatch); | ||
|
@@ -307,5 +307,8 @@ public HighlightFieldDescriptor<T> HighlightQuery(Func<QueryContainerDescriptor< | |
|
||
/// <inheritdoc/> | ||
public HighlightFieldDescriptor<T> Fragmenter(HighlighterFragmenter? fragmenter) => Assign(a => a.Fragmenter = fragmenter); | ||
|
||
/// <inheritdoc/> | ||
public HighlightFieldDescriptor<T> PhraseLimit(int phraseLimit) => Assign(a => a.PhraseLimit = phraseLimit); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Runtime.Serialization; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
|
||
namespace Nest | ||
{ | ||
/// <summary> | ||
/// Indicates if the highlighted text should be HTML encoded | ||
/// </summary> | ||
[JsonConverter(typeof(StringEnumConverter))] | ||
public enum HighlighterEncoder | ||
{ | ||
/// <summary> | ||
/// No encoding | ||
/// </summary> | ||
[EnumMember(Value = "default")] | ||
Default, | ||
/// <summary> | ||
/// Escapes HTML highlighting tags | ||
/// </summary> | ||
[EnumMember(Value = "html")] | ||
Html | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Runtime.Serialization; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
|
||
namespace Nest | ||
{ | ||
/// <summary> | ||
/// Sorts highlighted fragments | ||
/// </summary> | ||
[JsonConverter(typeof(StringEnumConverter))] | ||
public enum HighlighterOrder | ||
{ | ||
/// <summary> | ||
/// Sorts highlighted fragments by score. Only valid for the <see cref="HighlighterType.Unified"/> highligher | ||
/// </remarks> | ||
[EnumMember(Value = "score")] | ||
Score | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Runtime.Serialization; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
|
||
namespace Nest | ||
{ | ||
/// <summary> | ||
/// Use a built-in tag schema | ||
/// </summary> | ||
[JsonConverter(typeof(StringEnumConverter))] | ||
public enum HighlighterTagsSchema | ||
{ | ||
/// <summary> | ||
/// Use a specific "tag" schemas. | ||
/// </summary> | ||
/// <remarks> | ||
/// <para>Currently a single schema called "styled" with the following pre_tags:</para> | ||
/// <para><em class="hlt1">, <em class="hlt2">, <em class="hlt3">,</para> | ||
/// <para><em class="hlt4">, <em class="hlt5">, <em class="hlt6">,</para> | ||
/// <para><em class="hlt7">, <em class="hlt8">, <em class="hlt9">,</para> | ||
/// <para><em class="hlt10"></para> | ||
/// </remarks> | ||
[EnumMember(Value = "styled")] | ||
Styled | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No default value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can make it the default, but the client generally doesn't have default values for nullable enums. I suspect this had a default value more as a hint for the accepted string value.