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>
  • Loading branch information
gjunge authored Aug 20, 2023
1 parent 74bcaab commit 8ad8057
Show file tree
Hide file tree
Showing 4 changed files with 346 additions and 7 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Moved `OpenSearch.Client` request classes into their respective namespaces to match those in `OpenSearch.Net` ([#200](https://github.com/opensearch-project/opensearch-net/pull/200), [#202](https://github.com/opensearch-project/opensearch-net/pull/202), [#203](https://github.com/opensearch-project/opensearch-net/pull/203), [#205](https://github.com/opensearch-project/opensearch-net/pull/205), [#206](https://github.com/opensearch-project/opensearch-net/pull/206), [#207](https://github.com/opensearch-project/opensearch-net/pull/207), [#208](https://github.com/opensearch-project/opensearch-net/pull/208), [#209](https://github.com/opensearch-project/opensearch-net/pull/209))
- Removed support for the `net461` target ([#256](https://github.com/opensearch-project/opensearch-net/pull/256))

### 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.CodeAnalysis.CSharp` from 4.2.0 to 4.6.0
- Bumps `Microsoft.TestPlatform.ObjectModel` from 17.5.0 to 17.6.3
Expand Down Expand Up @@ -88,4 +91,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

[Unreleased]: https://github.com/opensearch-project/opensearch-net/compare/v1.4.0...main
[1.4.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.3.0...v1.4.0
[1.3.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.2.0...v1.3.0
[1.3.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.2.0...v1.3.0
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 8ad8057

Please sign in to comment.