public void PASS_CreateQuery()
        {
            SpanNearQuery query = new SpanNearQuery(new List<SpanQueryBase>(){
                    new SpanTermQuery("field", "value")
                });

            Assert.IsNotNull(query);
            Assert.AreEqual(1, query.Clauses.Count());
        }
        public void PASS_Serialize()
        {
            SpanNearQuery query = new SpanNearQuery(new List<SpanQueryBase>(){
                    new SpanTermQuery("field", "value")
                });
            string json = JsonConvert.SerializeObject(query);
            Assert.IsNotNull(json);

            string expectedJson = "{\"span_near\":{\"clauses\":[{\"span_term\":{\"field\":\"value\"}}],\"in_order\":false,\"collect_payloads\":false}}";

            Assert.AreEqual(expectedJson, json);
        }
 public void FAIL_CreateQuery()
 {
     try
     {
         SpanNearQuery query = new SpanNearQuery(new List<SpanQueryBase>() { null });
         Assert.Fail();
     }
     catch(ArgumentNullException ex)
     {
         Assert.AreEqual("clauses", ex.ParamName);
     }
 }
예제 #4
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            Dictionary<string, object> fieldDict = serializer.Deserialize<Dictionary<string, object>>(reader);
            if (fieldDict.ContainsKey(SpanQueryTypeEnum.Near.ToString()))
                fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict.First().Value.ToString());

            SpanNearQuery query = new SpanNearQuery(JsonConvert.DeserializeObject<IEnumerable<SpanQueryBase>>(fieldDict.GetString(_CLAUSES)));

            query.Slop = fieldDict.GetInt32OrNull(_SLOP);
            query.RequireMatchesInOrder = fieldDict.GetBoolOrDefault(_IN_ORDER);
            query.CollectPayloads = fieldDict.GetBoolOrDefault(_COLLECT_PAYLOADS);
            query.QueryName = fieldDict.GetStringOrDefault(QuerySerializer._QUERY_NAME);

            return query;
        }