From d196db1dc3e9f369d31ec0cab507dcfd7e6a75cd Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Thu, 23 Mar 2023 15:49:43 +0000 Subject: [PATCH] Updated completion suggestion based on spec fixes --- .../Core/Search/CompletionSuggester.g.cs | 86 +++++++++++++------ .../Types/Core/Search/RegexOptions.g.cs | 78 +++++++++++++++++ 2 files changed, 137 insertions(+), 27 deletions(-) create mode 100644 src/Elastic.Clients.Elasticsearch/_Generated/Types/Core/Search/RegexOptions.g.cs diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Core/Search/CompletionSuggester.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Core/Search/CompletionSuggester.g.cs index a809ad0f139..29d88073010 100644 --- a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Core/Search/CompletionSuggester.g.cs +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Core/Search/CompletionSuggester.g.cs @@ -37,10 +37,8 @@ public sealed partial class CompletionSuggester public Elastic.Clients.Elasticsearch.Field Field { get; set; } [JsonInclude, JsonPropertyName("fuzzy")] public Elastic.Clients.Elasticsearch.Core.Search.SuggestFuzziness? Fuzzy { get; set; } - [JsonInclude, JsonPropertyName("prefix")] - public string? Prefix { get; set; } [JsonInclude, JsonPropertyName("regex")] - public string? Regex { get; set; } + public Elastic.Clients.Elasticsearch.Core.Search.RegexOptions? Regex { get; set; } [JsonInclude, JsonPropertyName("size")] public int? Size { get; set; } [JsonInclude, JsonPropertyName("skip_duplicates")] @@ -63,8 +61,9 @@ public CompletionSuggesterDescriptor() : base() private Elastic.Clients.Elasticsearch.Core.Search.SuggestFuzziness? FuzzyValue { get; set; } private SuggestFuzzinessDescriptor FuzzyDescriptor { get; set; } private Action FuzzyDescriptorAction { get; set; } - private string? PrefixValue { get; set; } - private string? RegexValue { get; set; } + private Elastic.Clients.Elasticsearch.Core.Search.RegexOptions? RegexValue { get; set; } + private RegexOptionsDescriptor RegexDescriptor { get; set; } + private Action RegexDescriptorAction { get; set; } private int? SizeValue { get; set; } private bool? SkipDuplicatesValue { get; set; } @@ -116,15 +115,27 @@ public CompletionSuggesterDescriptor Fuzzy(Action Prefix(string? prefix) + public CompletionSuggesterDescriptor Regex(Elastic.Clients.Elasticsearch.Core.Search.RegexOptions? regex) { - PrefixValue = prefix; + RegexDescriptor = null; + RegexDescriptorAction = null; + RegexValue = regex; return Self; } - public CompletionSuggesterDescriptor Regex(string? regex) + public CompletionSuggesterDescriptor Regex(RegexOptionsDescriptor descriptor) { - RegexValue = regex; + RegexValue = null; + RegexDescriptorAction = null; + RegexDescriptor = descriptor; + return Self; + } + + public CompletionSuggesterDescriptor Regex(Action configure) + { + RegexValue = null; + RegexDescriptor = null; + RegexDescriptorAction = configure; return Self; } @@ -173,16 +184,20 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o JsonSerializer.Serialize(writer, FuzzyValue, options); } - if (!string.IsNullOrEmpty(PrefixValue)) + if (RegexDescriptor is not null) { - writer.WritePropertyName("prefix"); - writer.WriteStringValue(PrefixValue); + writer.WritePropertyName("regex"); + JsonSerializer.Serialize(writer, RegexDescriptor, options); } - - if (!string.IsNullOrEmpty(RegexValue)) + else if (RegexDescriptorAction is not null) + { + writer.WritePropertyName("regex"); + JsonSerializer.Serialize(writer, new RegexOptionsDescriptor(RegexDescriptorAction), options); + } + else if (RegexValue is not null) { writer.WritePropertyName("regex"); - writer.WriteStringValue(RegexValue); + JsonSerializer.Serialize(writer, RegexValue, options); } if (SizeValue.HasValue) @@ -215,8 +230,9 @@ public CompletionSuggesterDescriptor() : base() private Elastic.Clients.Elasticsearch.Core.Search.SuggestFuzziness? FuzzyValue { get; set; } private SuggestFuzzinessDescriptor FuzzyDescriptor { get; set; } private Action FuzzyDescriptorAction { get; set; } - private string? PrefixValue { get; set; } - private string? RegexValue { get; set; } + private Elastic.Clients.Elasticsearch.Core.Search.RegexOptions? RegexValue { get; set; } + private RegexOptionsDescriptor RegexDescriptor { get; set; } + private Action RegexDescriptorAction { get; set; } private int? SizeValue { get; set; } private bool? SkipDuplicatesValue { get; set; } @@ -274,15 +290,27 @@ public CompletionSuggesterDescriptor Fuzzy(Action co return Self; } - public CompletionSuggesterDescriptor Prefix(string? prefix) + public CompletionSuggesterDescriptor Regex(Elastic.Clients.Elasticsearch.Core.Search.RegexOptions? regex) { - PrefixValue = prefix; + RegexDescriptor = null; + RegexDescriptorAction = null; + RegexValue = regex; return Self; } - public CompletionSuggesterDescriptor Regex(string? regex) + public CompletionSuggesterDescriptor Regex(RegexOptionsDescriptor descriptor) { - RegexValue = regex; + RegexValue = null; + RegexDescriptorAction = null; + RegexDescriptor = descriptor; + return Self; + } + + public CompletionSuggesterDescriptor Regex(Action configure) + { + RegexValue = null; + RegexDescriptor = null; + RegexDescriptorAction = configure; return Self; } @@ -331,16 +359,20 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o JsonSerializer.Serialize(writer, FuzzyValue, options); } - if (!string.IsNullOrEmpty(PrefixValue)) + if (RegexDescriptor is not null) { - writer.WritePropertyName("prefix"); - writer.WriteStringValue(PrefixValue); + writer.WritePropertyName("regex"); + JsonSerializer.Serialize(writer, RegexDescriptor, options); } - - if (!string.IsNullOrEmpty(RegexValue)) + else if (RegexDescriptorAction is not null) + { + writer.WritePropertyName("regex"); + JsonSerializer.Serialize(writer, new RegexOptionsDescriptor(RegexDescriptorAction), options); + } + else if (RegexValue is not null) { writer.WritePropertyName("regex"); - writer.WriteStringValue(RegexValue); + JsonSerializer.Serialize(writer, RegexValue, options); } if (SizeValue.HasValue) diff --git a/src/Elastic.Clients.Elasticsearch/_Generated/Types/Core/Search/RegexOptions.g.cs b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Core/Search/RegexOptions.g.cs new file mode 100644 index 00000000000..df639a9f460 --- /dev/null +++ b/src/Elastic.Clients.Elasticsearch/_Generated/Types/Core/Search/RegexOptions.g.cs @@ -0,0 +1,78 @@ +// Licensed to Elasticsearch B.V under one or more agreements. +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +// See the LICENSE file in the project root for more information. +// +// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗ +// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝ +// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗ +// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝ +// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗ +// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝ +// ------------------------------------------------ +// +// This file is automatically generated. +// Please do not edit these files manually. +// +// ------------------------------------------------ + +#nullable restore + +using Elastic.Clients.Elasticsearch.Fluent; +using Elastic.Clients.Elasticsearch.Serialization; +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Elastic.Clients.Elasticsearch.Core.Search; + +public sealed partial class RegexOptions +{ + [JsonInclude, JsonPropertyName("flags")] + public Union? Flags { get; set; } + [JsonInclude, JsonPropertyName("max_determinized_states")] + public int? MaxDeterminizedStates { get; set; } +} + +public sealed partial class RegexOptionsDescriptor : SerializableDescriptor +{ + internal RegexOptionsDescriptor(Action configure) => configure.Invoke(this); + + public RegexOptionsDescriptor() : base() + { + } + + private Union? FlagsValue { get; set; } + private int? MaxDeterminizedStatesValue { get; set; } + + public RegexOptionsDescriptor Flags(Union? flags) + { + FlagsValue = flags; + return Self; + } + + public RegexOptionsDescriptor MaxDeterminizedStates(int? maxDeterminizedStates) + { + MaxDeterminizedStatesValue = maxDeterminizedStates; + return Self; + } + + protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) + { + writer.WriteStartObject(); + if (FlagsValue is not null) + { + writer.WritePropertyName("flags"); + JsonSerializer.Serialize(writer, FlagsValue, options); + } + + if (MaxDeterminizedStatesValue.HasValue) + { + writer.WritePropertyName("max_determinized_states"); + writer.WriteNumberValue(MaxDeterminizedStatesValue.Value); + } + + writer.WriteEndObject(); + } +} \ No newline at end of file