Skip to content

Commit

Permalink
Implement HighlightField level max_analyzer_offset.
Browse files Browse the repository at this point in the history
max_analyzer_offset can be set both on highlight in general, and on specific fields.
  • Loading branch information
gjunge committed Aug 19, 2023
1 parent 00776bb commit a0cfba0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/OpenSearch.Client/Search/Search/Highlighting/HighlightField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ public interface IHighlightField
[DataMember(Name = "matched_fields")]
Fields MatchedFields { get; set; }


/// <summary>
/// If this setting is set to a non-negative value, the highlighting stops at this defined maximum limit, and the
/// rest of the text is not processed, thus not highlighted and no error is returned.
/// </summary>
/// <remarks>Introduced in OpenSearch 2.2</remarks>
[DataMember(Name = "max_analyzer_offset")]
int? MaxAnalyzerOffset { get; set; }

[DataMember(Name = "max_fragment_length")]
int? MaxFragmentLength { get; set; }

Expand Down Expand Up @@ -191,6 +200,7 @@ public interface IHighlightField
/// </summary>
[DataMember(Name = "type")]
Union<HighlighterType, string> Type { get; set; }

}

public class HighlightField : IHighlightField
Expand Down Expand Up @@ -228,6 +238,9 @@ public class HighlightField : IHighlightField
/// <inheritdoc />
public Fields MatchedFields { get; set; }

/// <inheritdoc/>
public int? MaxAnalyzerOffset { get; set; }

/// <inheritdoc />
public int? MaxFragmentLength { get; set; }

Expand Down Expand Up @@ -273,6 +286,9 @@ public class HighlightFieldDescriptor<T> : DescriptorBase<HighlightFieldDescript
int? IHighlightField.FragmentSize { get; set; }
QueryContainer IHighlightField.HighlightQuery { get; set; }
Fields IHighlightField.MatchedFields { get; set; }

int? IHighlightField.MaxAnalyzerOffset { get; set; }

int? IHighlightField.MaxFragmentLength { get; set; }
int? IHighlightField.NoMatchSize { get; set; }
int? IHighlightField.NumberOfFragments { get; set; }
Expand Down Expand Up @@ -349,6 +365,9 @@ public HighlightFieldDescriptor<T> MatchedFields(Func<FieldsDescriptor<T>, IProm
public HighlightFieldDescriptor<T> HighlightQuery(Func<QueryContainerDescriptor<T>, QueryContainer> querySelector) =>
Assign(querySelector, (a, v) => a.HighlightQuery = v?.Invoke(new QueryContainerDescriptor<T>()));

/// <inheritdoc />
public HighlightFieldDescriptor<T> MaxAnalyzerOffset(int? maxAnalyzerOffset) => Assign(maxAnalyzerOffset, (a, v) => a.MaxAnalyzerOffset = v);

/// <inheritdoc />
public HighlightFieldDescriptor<T> MaxFragmentLength(int? maxFragmentLength) => Assign(maxFragmentLength, (a, v) => a.MaxFragmentLength = v);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public HighlightingUsageTestsWithMaxAnalyzerOffset(ReadOnlyCluster cluster, Endp
{ "fragment_size", 150 },
{ "fragmenter", "span" },
{ "number_of_fragments", 3 },
{ "no_match_size", 150 }
{ "no_match_size", 150 },
{ "max_analyzer_offset", 500 }
}
},
{
Expand Down Expand Up @@ -179,7 +180,8 @@ public HighlightingUsageTestsWithMaxAnalyzerOffset(ReadOnlyCluster cluster, Endp
.FragmentSize(150)
.Fragmenter(HighlighterFragmenter.Span)
.NumberOfFragments(3)
.NoMatchSize(150),
.NoMatchSize(150)
.MaxAnalyzerOffset(500),
fs => fs
.Field(p => p.LeadDeveloper.FirstName)
.Type(HighlighterType.Fvh)
Expand Down Expand Up @@ -236,7 +238,8 @@ public HighlightingUsageTestsWithMaxAnalyzerOffset(ReadOnlyCluster cluster, Endp
FragmentSize = 150,
Fragmenter = HighlighterFragmenter.Span,
NumberOfFragments = 3,
NoMatchSize = 150
NoMatchSize = 150,
MaxAnalyzerOffset = 500
}
},
{
Expand Down

0 comments on commit a0cfba0

Please sign in to comment.