コード例 #1
0
 public void PASS_CreateQuery()
 {
     StringRangeQuery query = new StringRangeQuery("field", "1");
     Assert.IsNotNull(query);
     Assert.AreEqual("field", query.Field);
     Assert.AreEqual("1", query.GreaterThan);
 }
コード例 #2
0
        public void PASS_Serializer()
        {
            StringRangeQuery query = new StringRangeQuery("field", "1");
            string json = JsonConvert.SerializeObject(query);
            Assert.IsNotNull(json);

            string expectedJson = "{\"range\":{\"field\":{\"gt\":\"1\"}}}";
            Assert.AreEqual(expectedJson, json);
        }
コード例 #3
0
 public void FAIL_CreateQuery_Range()
 {
     try
     {
         StringRangeQuery query = new StringRangeQuery("field");
         Assert.Fail();
     }
     catch (ArgumentNullException ex)
     {
         Assert.AreEqual("range", ex.ParamName);
     }
 }
コード例 #4
0
        private static RangeQueryBase BuildRangeQuery(string fieldName, Dictionary<string, object> fieldDict)
        {
            object value = fieldDict.First(x => x.Key != QuerySerializer._BOOST).Value;

            RangeQueryBase query = null;

            if (value is Int32 || value is Int64)
            {
                query = new IntegerRangeQuery(fieldName,
                    fieldDict.GetInt64OrNull(_GREATER_THAN),
                    fieldDict.GetInt64OrNull(_LESS_THAN),
                    fieldDict.GetInt64OrNull(_GREATER_THAN_OR_EQUAL_TO),
                    fieldDict.GetInt64OrNull(_LESS_THAN_OR_EQUAL_TO));
            }
            else if (value is Double || value is float)
            {
                query = new DoubleRangeQuery(fieldName,
                    fieldDict.GetDoubleOrNull(_GREATER_THAN),
                    fieldDict.GetDoubleOrNull(_LESS_THAN),
                    fieldDict.GetDoubleOrNull(_GREATER_THAN_OR_EQUAL_TO),
                    fieldDict.GetDoubleOrNull(_LESS_THAN_OR_EQUAL_TO));
            }
            else
            {
                try
                {
                    DateTime.Parse(value.ToString());
                    query = new DateTimeRangeQuery(fieldName,
                        fieldDict.GetDateTimeOrNull(_GREATER_THAN),
                        fieldDict.GetDateTimeOrNull(_LESS_THAN),
                        fieldDict.GetDateTimeOrNull(_GREATER_THAN_OR_EQUAL_TO),
                        fieldDict.GetDateTimeOrNull(_LESS_THAN_OR_EQUAL_TO));
                }
                catch
                {
                    query = new StringRangeQuery(fieldName,
                        fieldDict.GetStringOrDefault(_GREATER_THAN),
                        fieldDict.GetStringOrDefault(_LESS_THAN),
                        fieldDict.GetStringOrDefault(_GREATER_THAN_OR_EQUAL_TO),
                        fieldDict.GetStringOrDefault(_LESS_THAN_OR_EQUAL_TO));
                }
            }

            query.QueryName = fieldDict.GetStringOrDefault(QuerySerializer._QUERY_NAME);

            return query;
        }