示例#1
0
		private static IRangeQuery GetRangeQuery(JsonSerializer serializer, JObject jo)
		{
			var isNumeric = false;
			var isLong = false;

			foreach (var property in jo.Properties())
			{
				if (property.Name == "format" || property.Name == "time_zone")
					return FromJson.ReadAs<DateRangeQuery>(jo.CreateReader(), serializer);

				if (_rangeKeys.Contains(property.Name))
				{
					if (property.Value.Type == JTokenType.Float)
						isNumeric = true;
					else if (property.Value.Type == JTokenType.Integer)
						isLong = true;
				}
			}
			if (isNumeric)
				return FromJson.ReadAs<NumericRangeQuery>(jo.CreateReader(), serializer);
			if (isLong)
				return FromJson.ReadAs<LongRangeQuery>(jo.CreateReader(), serializer);

			return FromJson.ReadAs<DateRangeQuery>(jo.CreateReader(), serializer);
		}
示例#2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var jo     = JObject.Load(reader);
            var filter = jo.Property("filter")?.Value.ToObject <QueryContainer>(serializer);
            var weight = jo.Property("weight")?.Value.ToObject <double?>();

            ;
            IScoreFunction function = null;

            foreach (var prop in jo.Properties())
            {
                switch (prop.Name)
                {
                case "exp":
                case "gauss":
                case "linear":
                    var properties = prop.Value.Value <JObject>().Properties().ToList();
                    var fieldProp  = properties.First(p => p.Name != "multi_value_mode");
                    var field      = fieldProp.Name;
                    var f          = ReadDecayFunction(prop.Name, fieldProp.Value.Value <JObject>(), serializer);
                    f.Field = field;
                    var mv = properties.FirstOrDefault(p => p.Name == "multi_value_mode")?.Value;
                    if (mv != null)
                    {
                        f.MultiValueMode = serializer.Deserialize <MultiValueMode>(mv.CreateReader());
                    }
                    function = f;

                    break;

                case "random_score":
                    function = FromJson.ReadAs <RandomScoreFunction>(prop.Value.Value <JObject>().CreateReader(), serializer);
                    break;

                case "field_value_factor":
                    function = FromJson.ReadAs <FieldValueFactorFunction>(prop.Value.Value <JObject>().CreateReader(), serializer);
                    break;

                case "script_score":
                    function = FromJson.ReadAs <ScriptScoreFunction>(prop.Value.Value <JObject>().CreateReader(), serializer);
                    break;
                }
            }
            if (function == null && weight.HasValue)
            {
                function = new WeightFunction {
                    Weight = weight
                }
            }
            ;
            else if (function == null)
            {
                return(null);                                   //throw new Exception("error deserializing function score function");
            }
            function.Weight = weight;
            function.Filter = filter;
            return(function);
        }
示例#3
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            ISort sort = null;

            reader.Read();
            var field = reader.Value as string;

            if (field == "_geo_distance")
            {
                reader.Read();
                var jObject         = JObject.Load(reader);
                var geoLocationProp = jObject.Properties().First(p => p.Value.Type == JTokenType.Array);
                using (var r = jObject.CreateReader())
                {
                    var s = FromJson.ReadAs <GeoDistanceSort>(r, serializer);
                    s.Field = geoLocationProp.Name;
                    using (var rr = geoLocationProp.Value.CreateReader())
                        s.Points = FromJson.ReadAs <List <GeoLocation> >(rr, serializer);
                    sort = s;
                }
            }
            else if (field == "_script")
            {
                reader.Read();
                var s = FromJson.ReadAs <ScriptSort>(reader, serializer);
                sort = s;
            }
            else
            {
                reader.Read();
                var s = FromJson.ReadAs <SortField>(reader, serializer);
                s.Field = field;
                sort    = s;
            }
            reader.Read();
            return(sort);
        }
示例#4
0
 private TProperty ReadProperty <TProperty>(JObject j, JsonSerializer s) where TProperty : IProperty =>
 FromJson.ReadAs <TProperty>(j.CreateReader(), s);
示例#5
0
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) =>
 FromJson.ReadAs <T>(reader, serializer);