This repository has been archived by the owner on Jul 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
TextQueryConverter.cs
77 lines (68 loc) · 2.02 KB
/
TextQueryConverter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using Newtonsoft.Json;
namespace ElasticSearch.Client.QueryDSL
{
internal class TextQueryConverter:JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
TextQuery term = (TextQuery)value;
if (term != null)
{
writer.WriteStartObject();
writer.WritePropertyName("text");
writer.WriteStartObject();
writer.WritePropertyName(term.Field);
writer.WriteStartObject();
writer.WritePropertyName("query");
writer.WriteValue(term.Text);
if(!string.IsNullOrEmpty(term.QueryType))
{
writer.WritePropertyName("type");
writer.WriteValue(term.QueryType);
}
if(term.Operator!=default(Operator))
{
writer.WritePropertyName("operator");
writer.WriteValue(term.Operator.ToString().ToLower());
}
if(term.Slop!=default(int))
{
writer.WritePropertyName("slop");
writer.WriteValue(term.Slop);
}
if (!Equals(term.Fuzziness, default(float)))
{
writer.WritePropertyName("fuzziness");
writer.WriteValue(term.Fuzziness);
}
if (!Equals(term.Boost, default(float)))
{
writer.WritePropertyName("boost");
writer.WriteValue(term.Boost);
}
if (!Equals(term.PrefixLength, default(int)))
{
writer.WritePropertyName("prefix_length");
writer.WriteValue(term.PrefixLength);
}
if (!Equals(term.MaxExpansions, default(int)))
{
writer.WritePropertyName("max_expansions");
writer.WriteValue(term.MaxExpansions);
}
writer.WriteEndObject();
writer.WriteEndObject();
writer.WriteEndObject();
}
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
throw new NotImplementedException();
}
public override bool CanConvert(Type objectType)
{
return typeof(TextQuery).IsAssignableFrom(objectType);
}
}
}