Skip to content

Commit

Permalink
Add missing Field property to IntervalsQuery (#8229) (#8231)
Browse files Browse the repository at this point in the history
Co-authored-by: Florian Bernd <git@flobernd.de>
  • Loading branch information
github-actions[bot] and flobernd authored Jun 11, 2024
1 parent f8c8ed2 commit 3d795e8
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ internal IntervalsQuery(string variantName, object variant)
/// </summary>
[JsonInclude, JsonPropertyName("boost")]
public float? Boost { get; set; }
[JsonInclude, JsonPropertyName("field")]
public Elastic.Clients.Elasticsearch.Serverless.Field Field { get; set; }
[JsonInclude, JsonPropertyName("_name")]
public string? QueryName { get; set; }

Expand All @@ -83,6 +85,9 @@ public override IntervalsQuery Read(ref Utf8JsonReader reader, Type typeToConver
throw new JsonException("Expected start token.");
}

reader.Read();
var fieldName = reader.GetString();
reader.Read();
object? variantValue = default;
string? variantNameValue = default;
float? boostValue = default;
Expand Down Expand Up @@ -158,14 +163,22 @@ public override IntervalsQuery Read(ref Utf8JsonReader reader, Type typeToConver
throw new JsonException($"Unknown property name '{propertyName}' received while deserializing the 'IntervalsQuery' from the response.");
}

reader.Read();
var result = new IntervalsQuery(variantNameValue, variantValue);
result.Boost = boostValue;
result.Field = fieldName;
result.QueryName = queryNameValue;
return result;
}

public override void Write(Utf8JsonWriter writer, IntervalsQuery value, JsonSerializerOptions options)
{
if (value.Field is null)
throw new JsonException("Unable to serialize IntervalsQuery because the `Field` property is not set. Field name queries must include a valid field name.");
if (!options.TryGetClientSettings(out var settings))
throw new JsonException("Unable to retrieve client settings required to infer field.");
writer.WriteStartObject();
writer.WritePropertyName(settings.Inferrer.Field(value.Field));
writer.WriteStartObject();
if (value.Boost.HasValue)
{
Expand Down Expand Up @@ -206,6 +219,7 @@ public override void Write(Utf8JsonWriter writer, IntervalsQuery value, JsonSeri
}

writer.WriteEndObject();
writer.WriteEndObject();
}
}

Expand Down Expand Up @@ -241,6 +255,7 @@ private IntervalsQueryDescriptor<TDocument> Set(object variant, string variantNa
}

private float? BoostValue { get; set; }
private Elastic.Clients.Elasticsearch.Serverless.Field FieldValue { get; set; }
private string? QueryNameValue { get; set; }

/// <summary>
Expand All @@ -252,6 +267,24 @@ public IntervalsQueryDescriptor<TDocument> Boost(float? boost)
return Self;
}

public IntervalsQueryDescriptor<TDocument> Field(Elastic.Clients.Elasticsearch.Serverless.Field field)
{
FieldValue = field;
return Self;
}

public IntervalsQueryDescriptor<TDocument> Field<TValue>(Expression<Func<TDocument, TValue>> field)
{
FieldValue = field;
return Self;
}

public IntervalsQueryDescriptor<TDocument> Field(Expression<Func<TDocument, object>> field)
{
FieldValue = field;
return Self;
}

public IntervalsQueryDescriptor<TDocument> QueryName(string? queryName)
{
QueryNameValue = queryName;
Expand All @@ -273,6 +306,10 @@ public IntervalsQueryDescriptor<TDocument> QueryName(string? queryName)

protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
{
if (FieldValue is null)
throw new JsonException("Unable to serialize field name query descriptor with a null field. Ensure you use a suitable descriptor constructor or call the Field method, passing a non-null value for the field argument.");
writer.WriteStartObject();
writer.WritePropertyName(settings.Inferrer.Field(FieldValue));
writer.WriteStartObject();
if (BoostValue.HasValue)
{
Expand Down Expand Up @@ -300,6 +337,7 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
}

writer.WriteEndObject();
writer.WriteEndObject();
}
}

Expand Down Expand Up @@ -335,6 +373,7 @@ private IntervalsQueryDescriptor Set(object variant, string variantName)
}

private float? BoostValue { get; set; }
private Elastic.Clients.Elasticsearch.Serverless.Field FieldValue { get; set; }
private string? QueryNameValue { get; set; }

/// <summary>
Expand All @@ -346,6 +385,24 @@ public IntervalsQueryDescriptor Boost(float? boost)
return Self;
}

public IntervalsQueryDescriptor Field(Elastic.Clients.Elasticsearch.Serverless.Field field)
{
FieldValue = field;
return Self;
}

public IntervalsQueryDescriptor Field<TDocument, TValue>(Expression<Func<TDocument, TValue>> field)
{
FieldValue = field;
return Self;
}

public IntervalsQueryDescriptor Field<TDocument>(Expression<Func<TDocument, object>> field)
{
FieldValue = field;
return Self;
}

public IntervalsQueryDescriptor QueryName(string? queryName)
{
QueryNameValue = queryName;
Expand All @@ -367,6 +424,10 @@ public IntervalsQueryDescriptor QueryName(string? queryName)

protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
{
if (FieldValue is null)
throw new JsonException("Unable to serialize field name query descriptor with a null field. Ensure you use a suitable descriptor constructor or call the Field method, passing a non-null value for the field argument.");
writer.WriteStartObject();
writer.WritePropertyName(settings.Inferrer.Field(FieldValue));
writer.WriteStartObject();
if (BoostValue.HasValue)
{
Expand Down Expand Up @@ -394,5 +455,6 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
}

writer.WriteEndObject();
writer.WriteEndObject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ internal IntervalsQuery(string variantName, object variant)
/// </summary>
[JsonInclude, JsonPropertyName("boost")]
public float? Boost { get; set; }
[JsonInclude, JsonPropertyName("field")]
public Elastic.Clients.Elasticsearch.Field Field { get; set; }
[JsonInclude, JsonPropertyName("_name")]
public string? QueryName { get; set; }

Expand All @@ -83,6 +85,9 @@ public override IntervalsQuery Read(ref Utf8JsonReader reader, Type typeToConver
throw new JsonException("Expected start token.");
}

reader.Read();
var fieldName = reader.GetString();
reader.Read();
object? variantValue = default;
string? variantNameValue = default;
float? boostValue = default;
Expand Down Expand Up @@ -158,14 +163,22 @@ public override IntervalsQuery Read(ref Utf8JsonReader reader, Type typeToConver
throw new JsonException($"Unknown property name '{propertyName}' received while deserializing the 'IntervalsQuery' from the response.");
}

reader.Read();
var result = new IntervalsQuery(variantNameValue, variantValue);
result.Boost = boostValue;
result.Field = fieldName;
result.QueryName = queryNameValue;
return result;
}

public override void Write(Utf8JsonWriter writer, IntervalsQuery value, JsonSerializerOptions options)
{
if (value.Field is null)
throw new JsonException("Unable to serialize IntervalsQuery because the `Field` property is not set. Field name queries must include a valid field name.");
if (!options.TryGetClientSettings(out var settings))
throw new JsonException("Unable to retrieve client settings required to infer field.");
writer.WriteStartObject();
writer.WritePropertyName(settings.Inferrer.Field(value.Field));
writer.WriteStartObject();
if (value.Boost.HasValue)
{
Expand Down Expand Up @@ -206,6 +219,7 @@ public override void Write(Utf8JsonWriter writer, IntervalsQuery value, JsonSeri
}

writer.WriteEndObject();
writer.WriteEndObject();
}
}

Expand Down Expand Up @@ -241,6 +255,7 @@ private IntervalsQueryDescriptor<TDocument> Set(object variant, string variantNa
}

private float? BoostValue { get; set; }
private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; }
private string? QueryNameValue { get; set; }

/// <summary>
Expand All @@ -252,6 +267,24 @@ public IntervalsQueryDescriptor<TDocument> Boost(float? boost)
return Self;
}

public IntervalsQueryDescriptor<TDocument> Field(Elastic.Clients.Elasticsearch.Field field)
{
FieldValue = field;
return Self;
}

public IntervalsQueryDescriptor<TDocument> Field<TValue>(Expression<Func<TDocument, TValue>> field)
{
FieldValue = field;
return Self;
}

public IntervalsQueryDescriptor<TDocument> Field(Expression<Func<TDocument, object>> field)
{
FieldValue = field;
return Self;
}

public IntervalsQueryDescriptor<TDocument> QueryName(string? queryName)
{
QueryNameValue = queryName;
Expand All @@ -273,6 +306,10 @@ public IntervalsQueryDescriptor<TDocument> QueryName(string? queryName)

protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
{
if (FieldValue is null)
throw new JsonException("Unable to serialize field name query descriptor with a null field. Ensure you use a suitable descriptor constructor or call the Field method, passing a non-null value for the field argument.");
writer.WriteStartObject();
writer.WritePropertyName(settings.Inferrer.Field(FieldValue));
writer.WriteStartObject();
if (BoostValue.HasValue)
{
Expand Down Expand Up @@ -300,6 +337,7 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
}

writer.WriteEndObject();
writer.WriteEndObject();
}
}

Expand Down Expand Up @@ -335,6 +373,7 @@ private IntervalsQueryDescriptor Set(object variant, string variantName)
}

private float? BoostValue { get; set; }
private Elastic.Clients.Elasticsearch.Field FieldValue { get; set; }
private string? QueryNameValue { get; set; }

/// <summary>
Expand All @@ -346,6 +385,24 @@ public IntervalsQueryDescriptor Boost(float? boost)
return Self;
}

public IntervalsQueryDescriptor Field(Elastic.Clients.Elasticsearch.Field field)
{
FieldValue = field;
return Self;
}

public IntervalsQueryDescriptor Field<TDocument, TValue>(Expression<Func<TDocument, TValue>> field)
{
FieldValue = field;
return Self;
}

public IntervalsQueryDescriptor Field<TDocument>(Expression<Func<TDocument, object>> field)
{
FieldValue = field;
return Self;
}

public IntervalsQueryDescriptor QueryName(string? queryName)
{
QueryNameValue = queryName;
Expand All @@ -367,6 +424,10 @@ public IntervalsQueryDescriptor QueryName(string? queryName)

protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
{
if (FieldValue is null)
throw new JsonException("Unable to serialize field name query descriptor with a null field. Ensure you use a suitable descriptor constructor or call the Field method, passing a non-null value for the field argument.");
writer.WriteStartObject();
writer.WritePropertyName(settings.Inferrer.Field(FieldValue));
writer.WriteStartObject();
if (BoostValue.HasValue)
{
Expand Down Expand Up @@ -394,5 +455,6 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
}

writer.WriteEndObject();
writer.WriteEndObject();
}
}

0 comments on commit 3d795e8

Please sign in to comment.