Skip to content

Commit

Permalink
Fixes opensearch-project#321: fix highlight max_analyzer_offset field…
Browse files Browse the repository at this point in the history
… name to match OS 2.2.0 (opensearch-project#322)

* Fixes opensearch-project#321: fix highlight max_analyzer_offset field name to match OS 2.2.0

Signed-off-by: Gideon Junge <gjunge@gmail.com>

* extend existing highlighting unit test

Signed-off-by: Gideon Junge <gjunge@gmail.com>

* Create > 2.2.0 unit test

Signed-off-by: Gideon Junge <gjunge@gmail.com>

* Implement HighlightField level max_analyzer_offset

max_analyzer_offset can be set both on highlight in general, and on specific fields.

Signed-off-by: Gideon Junge <gjunge@gmail.com>

---------

Signed-off-by: Gideon Junge <gjunge@gmail.com>
(cherry picked from commit 8ad8057)
  • Loading branch information
gjunge authored and Xtansia committed Aug 20, 2023
1 parent 261524c commit 479c9b9
Show file tree
Hide file tree
Showing 4 changed files with 345 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]
### Fixed
- Fix highlight max_analyzer_offset field name to match with the one introduced in OpenSearch 2.2.0 ([#322](https://github.com/opensearch-project/opensearch-net/pull/322))

### Dependencies
- Bumps `Microsoft.TestPlatform.ObjectModel` from 17.5.0 to 17.6.3
- Bumps `JunitXml.TestLogger` from 3.0.124 to 3.0.134
Expand Down
13 changes: 7 additions & 6 deletions src/OpenSearch.Client/Search/Search/Highlighting/Highlight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ public interface IHighlight
/// 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>
[DataMember(Name ="max_analyzed_offset")]
int? MaxAnalyzedOffset { get; set; }
/// <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 @@ -210,7 +211,7 @@ public class Highlight : IHighlight
public QueryContainer HighlightQuery { get; set; }

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

/// <inheritdoc/>
public int? MaxFragmentLength { get; set; }
Expand Down Expand Up @@ -258,7 +259,7 @@ public class HighlightDescriptor<T> : DescriptorBase<HighlightDescriptor<T>, IHi
int? IHighlight.FragmentOffset { get; set; }
int? IHighlight.FragmentSize { get; set; }
QueryContainer IHighlight.HighlightQuery { get; set; }
int? IHighlight.MaxAnalyzedOffset { get; set; }
int? IHighlight.MaxAnalyzerOffset { get; set; }
int? IHighlight.MaxFragmentLength { get; set; }
int? IHighlight.NoMatchSize { get; set; }
int? IHighlight.NumberOfFragments { get; set; }
Expand Down Expand Up @@ -323,8 +324,8 @@ public HighlightDescriptor<T> HighlightQuery(Func<QueryContainerDescriptor<T>, Q
/// <inheritdoc cref="IHighlight.BoundaryMaxScan" />
public HighlightDescriptor<T> BoundaryMaxScan(int? boundaryMaxScan) => Assign(boundaryMaxScan, (a, v) => a.BoundaryMaxScan = v);

/// <inheritdoc cref="IHighlight.MaxAnalyzedOffset" />
public HighlightDescriptor<T> MaxAnalyzedOffset(int? maxAnalyzedOffset) => Assign(maxAnalyzedOffset, (a, v) => a.MaxAnalyzedOffset = v);
/// <inheritdoc cref="IHighlight.MaxAnalyzerOffset" />
public HighlightDescriptor<T> MaxAnalyzerOffset(int? maxAnalyzerOffset) => Assign(maxAnalyzerOffset, (a, v) => a.MaxAnalyzerOffset = v);

/// <inheritdoc cref="IHighlight.MaxFragmentLength" />
public HighlightDescriptor<T> MaxFragmentLength(int? maxFragmentLength) => Assign(maxFragmentLength, (a, v) => a.MaxFragmentLength = v);
Expand Down
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
Loading

0 comments on commit 479c9b9

Please sign in to comment.