/// <summary> /// fuzzy query on a numeric field will result in a range query “around” the value using the min_similarity value /// </summary> /// <param name="selector"></param> public QueryContainer FuzzyDate(Action <FuzzyDateQueryDescriptor <T> > selector) { var query = new FuzzyDateQueryDescriptor <T>(); selector(query); return(this.New(query, q => q.Fuzzy = query)); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var j = JObject.Load(reader); if (!j.HasValues) { return(null); } var firstProp = j.Properties().FirstOrDefault(); if (firstProp == null) { return(null); } var field = firstProp.Name; var jo = firstProp.Value.Value <JObject>(); if (jo == null) { return(null); } JToken v = null; if (!jo.TryGetValue("value", out v)) { return(null); } IFuzzyQuery fq = null; if (v.Type == JTokenType.Date) { fq = new FuzzyDateQueryDescriptor <object>(); } else if (v.Type == JTokenType.String) { fq = new FuzzyQueryDescriptor <object>(); } else if (v.Type == JTokenType.Integer || v.Type == JTokenType.Float) { fq = new FuzzyNumericQueryDescriptor <object>(); } else { return(null); } fq.Field = field; fq.Boost = GetPropValue <double?>(jo, "boost"); fq.Fuzziness = GetPropValue <string>(jo, "fuzziness"); fq.MaxExpansions = GetPropValue <int?>(jo, "max_expansions"); fq.UnicodeAware = GetPropValue <bool?>(jo, "unicode_aware"); fq.Transpositions = GetPropValue <bool?>(jo, "transpositions"); var rewriteString = GetPropValue <string>(jo, "rewrite"); if (!rewriteString.IsNullOrEmpty()) { fq.Rewrite = Enum.Parse(typeof(RewriteMultiTerm), rewriteString) as RewriteMultiTerm?; } if (fq is IStringFuzzyQuery) { var fqs = fq as IStringFuzzyQuery; fqs.PrefixLength = GetPropValue <int?>(jo, "prefix_length"); fqs.Value = GetPropValue <string>(jo, "value"); } if (fq is IFuzzyDateQuery) { var fdq = fq as IFuzzyDateQuery; fdq.Value = GetPropValue <DateTime?>(jo, "value"); } if (fq is IFuzzyNumericQuery) { var fnq = fq as IFuzzyNumericQuery; fnq.Value = GetPropValue <double?>(jo, "value"); } return(fq); }