コード例 #1
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(_DIS_MAX))
                fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict.First().Value.ToString());

            DisjunctionMaxQuery query = new DisjunctionMaxQuery();
            query.TieBreaker = fieldDict.GetDouble(_TIE_BREAKER, _TIE_BREAKER_DEFAULT);
            query.Boost = fieldDict.GetDouble(QuerySerializer._BOOST, QuerySerializer._BOOST_DEFAULT);
            query.Queries = JsonConvert.DeserializeObject<IEnumerable<IQuery>>(fieldDict.GetString(_QUERIES));
            query.QueryName = fieldDict.GetStringOrDefault(QuerySerializer._QUERY_NAME);
            return query;
        }
コード例 #2
0
        public void PASS_CreateQuery()
        {
            DisjunctionMaxQuery query = new DisjunctionMaxQuery(
                    new List<IQuery>()
                    {
                        new TermQuery("field", "value1"),
                        new TermQuery("field", "value2")
                    }
                );

            Assert.IsNotNull(query);
            Assert.AreEqual(2, query.Queries.Count());
        }
コード例 #3
0
        public void PASS_Serialize()
        {
            DisjunctionMaxQuery query = new DisjunctionMaxQuery(
                    new List<IQuery>()
                    {
                        new TermQuery("field", "value1"),
                        new TermQuery("field", "value2")
                    }
                );

            string json = JsonConvert.SerializeObject(query);
            Assert.IsNotNull(json);

            string expectedJson = "{\"dis_max\":{\"queries\":[{\"term\":{\"field\":\"value1\"}},{\"term\":{\"field\":\"value2\"}}]}}";
            Assert.AreEqual(expectedJson, json);
        }
コード例 #4
0
        public void FAIL_CreateQuery_Queries()
        {
            try
            {
                DisjunctionMaxQuery query = new DisjunctionMaxQuery(
                    new List<IQuery>()
                    {
                    }
                );

                Assert.Fail();
            }
            catch (ArgumentNullException argEx)
            {
                Assert.AreEqual("queries", argEx.ParamName);
            }
        }