Skip to content

Fix CompletionSuggester based on spec fixes. #7456

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

Merged
merged 1 commit into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -63,8 +61,9 @@ public CompletionSuggesterDescriptor() : base()
private Elastic.Clients.Elasticsearch.Core.Search.SuggestFuzziness? FuzzyValue { get; set; }
private SuggestFuzzinessDescriptor FuzzyDescriptor { get; set; }
private Action<SuggestFuzzinessDescriptor> 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<RegexOptionsDescriptor> RegexDescriptorAction { get; set; }
private int? SizeValue { get; set; }
private bool? SkipDuplicatesValue { get; set; }

Expand Down Expand Up @@ -116,15 +115,27 @@ public CompletionSuggesterDescriptor<TDocument> Fuzzy(Action<SuggestFuzzinessDes
return Self;
}

public CompletionSuggesterDescriptor<TDocument> Prefix(string? prefix)
public CompletionSuggesterDescriptor<TDocument> Regex(Elastic.Clients.Elasticsearch.Core.Search.RegexOptions? regex)
{
PrefixValue = prefix;
RegexDescriptor = null;
RegexDescriptorAction = null;
RegexValue = regex;
return Self;
}

public CompletionSuggesterDescriptor<TDocument> Regex(string? regex)
public CompletionSuggesterDescriptor<TDocument> Regex(RegexOptionsDescriptor descriptor)
{
RegexValue = regex;
RegexValue = null;
RegexDescriptorAction = null;
RegexDescriptor = descriptor;
return Self;
}

public CompletionSuggesterDescriptor<TDocument> Regex(Action<RegexOptionsDescriptor> configure)
{
RegexValue = null;
RegexDescriptor = null;
RegexDescriptorAction = configure;
return Self;
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -215,8 +230,9 @@ public CompletionSuggesterDescriptor() : base()
private Elastic.Clients.Elasticsearch.Core.Search.SuggestFuzziness? FuzzyValue { get; set; }
private SuggestFuzzinessDescriptor FuzzyDescriptor { get; set; }
private Action<SuggestFuzzinessDescriptor> 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<RegexOptionsDescriptor> RegexDescriptorAction { get; set; }
private int? SizeValue { get; set; }
private bool? SkipDuplicatesValue { get; set; }

Expand Down Expand Up @@ -274,15 +290,27 @@ public CompletionSuggesterDescriptor Fuzzy(Action<SuggestFuzzinessDescriptor> 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<RegexOptionsDescriptor> configure)
{
RegexValue = null;
RegexDescriptor = null;
RegexDescriptorAction = configure;
return Self;
}

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<int?, string?>? Flags { get; set; }
[JsonInclude, JsonPropertyName("max_determinized_states")]
public int? MaxDeterminizedStates { get; set; }
}

public sealed partial class RegexOptionsDescriptor : SerializableDescriptor<RegexOptionsDescriptor>
{
internal RegexOptionsDescriptor(Action<RegexOptionsDescriptor> configure) => configure.Invoke(this);

public RegexOptionsDescriptor() : base()
{
}

private Union<int?, string?>? FlagsValue { get; set; }
private int? MaxDeterminizedStatesValue { get; set; }

public RegexOptionsDescriptor Flags(Union<int?, string?>? 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();
}
}