Skip to content

Commit b53cea7

Browse files
committed
Merge branch '2.x' into enhancement/2.x-get-aliases-converter
2 parents a580cdf + 127e9a6 commit b53cea7

File tree

1 file changed

+9
-87
lines changed

1 file changed

+9
-87
lines changed

src/Nest/QueryDsl/Specialized/Script/ScriptQueryConverter.cs

Lines changed: 9 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ namespace Nest
88
{
99
internal class ScriptQueryConverter : JsonConverter
1010
{
11-
private readonly VerbatimDictionaryKeysJsonConverter _dictionaryConverter =
12-
new VerbatimDictionaryKeysJsonConverter();
13-
14-
private readonly PropertyJsonConverter _elasticTypeConverter = new PropertyJsonConverter();
15-
1611
public override bool CanRead => true;
1712
public override bool CanWrite => true;
1813
public override bool CanConvert(Type objectType) => true;
@@ -40,7 +35,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
4035

4136
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
4237
{
43-
var r = new ScriptQuery();
38+
var query = new ScriptQuery();
4439
JObject o = JObject.Load(reader);
4540
var properties = o.Properties().ToListOrNullIfEmpty();
4641
var scriptProperty = properties.FirstOrDefault(p => p.Name == "script");
@@ -52,102 +47,29 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
5247
switch (p.Name)
5348
{
5449
case "_name":
55-
r.Name = p.Value.Value<string>();
56-
break;
57-
case "boost":
58-
r.Boost = p.Value.Value<double>();
59-
break;
60-
case "id":
61-
r.Id = p.Value.Value<string>();
62-
break;
63-
case "file":
64-
r.File = p.Value.Value<string>();
65-
break;
66-
case "inline":
67-
r.Inline = p.Value.Value<string>();
68-
break;
69-
case "lang":
70-
r.Lang = p.Value.Value<string>();
71-
break;
72-
case "params":
73-
r.Params = p.Value.ToObject<Dictionary<string, object>>();
74-
break;
75-
}
76-
}
77-
return r;
78-
}
79-
}
80-
81-
82-
83-
internal class SimpleScriptQueryConverter : JsonConverter
84-
{
85-
private readonly VerbatimDictionaryKeysJsonConverter _dictionaryConverter =
86-
new VerbatimDictionaryKeysJsonConverter();
87-
88-
private readonly PropertyJsonConverter _elasticTypeConverter = new PropertyJsonConverter();
89-
90-
public override bool CanRead => true;
91-
public override bool CanWrite => true;
92-
public override bool CanConvert(Type objectType) => true;
93-
94-
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
95-
{
96-
var v = value as IScriptQuery;
97-
if (v == null) return;
98-
99-
writer.WriteStartObject();
100-
if (!v.Name.IsNullOrEmpty()) writer.WriteProperty(serializer, "_name", v.Name);
101-
if (v.Boost != null) writer.WriteProperty(serializer, "boost", v.Boost);
102-
//writer.WritePropertyName("script");
103-
writer.WriteStartObject();
104-
{
105-
if (v.Id != null) writer.WriteProperty(serializer, "id", v.Id);
106-
if (v.File != null) writer.WriteProperty(serializer, "file", v.File);
107-
if (v.Inline != null) writer.WriteProperty(serializer, "inline", v.Inline);
108-
if (v.Lang != null) writer.WriteProperty(serializer, "lang", v.Lang);
109-
if (v.Params != null) writer.WriteProperty(serializer, "params", v.Params);
110-
}
111-
//writer.WriteEndObject();
112-
writer.WriteEndObject();
113-
}
114-
115-
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
116-
{
117-
var r = new ScriptQuery();
118-
JObject o = JObject.Load(reader);
119-
var properties = o.Properties().ToListOrNullIfEmpty();
120-
//var scriptProperty = properties.First(p=>p.Name == "script");
121-
//properties.AddRange(scriptProperty.Value.Value<JObject>().Properties());
122-
123-
foreach (var p in properties)
124-
{
125-
switch (p.Name)
126-
{
127-
case "_name":
128-
r.Name = p.Value.Value<string>();
50+
query.Name = p.Value.Value<string>();
12951
break;
13052
case "boost":
131-
r.Boost = p.Value.Value<double>();
53+
query.Boost = p.Value.Value<double>();
13254
break;
13355
case "id":
134-
r.Id = p.Value.Value<string>();
56+
query.Id = p.Value.Value<string>();
13557
break;
13658
case "file":
137-
r.File = p.Value.Value<string>();
59+
query.File = p.Value.Value<string>();
13860
break;
13961
case "inline":
140-
r.Inline = p.Value.Value<string>();
62+
query.Inline = p.Value.Value<string>();
14163
break;
14264
case "lang":
143-
r.Lang = p.Value.Value<string>();
65+
query.Lang = p.Value.Value<string>();
14466
break;
14567
case "params":
146-
r.Params = p.Value.ToObject<Dictionary<string, object>>();
68+
query.Params = p.Value.ToObject<Dictionary<string, object>>();
14769
break;
14870
}
14971
}
150-
return r;
72+
return query;
15173
}
15274
}
15375
}

0 commit comments

Comments
 (0)