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(_CONSTANT_SCORE))
                fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict.First().Value.ToString());

            ConstantScoreQueryBase constantScore = null;

            if (fieldDict.ContainsKey(_QUERY))
            { 
                Dictionary<string, object> queryDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict[_QUERY].ToString());
                QueryTypeEnum queryType = QueryTypeEnum.ConstantScoreQuery;
                queryType = QueryTypeEnum.Find(queryDict.First().Key);
                IQuery query = JsonConvert.DeserializeObject(queryDict.First().Value.ToString(), queryType.ImplementationType) as IQuery;
                constantScore = new ConstantScoreQuery(query);
            }
            else if (fieldDict.ContainsKey(_FILTER))
            {
                Dictionary<string, object> filterDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict[_FILTER].ToString());
                FilterTypeEnum filterType = FilterTypeEnum.Term;
                filterType = FilterTypeEnum.Find(filterDict.First().Key);
                IFilter filter = JsonConvert.DeserializeObject(filterDict.First().Value.ToString(), filterType.ImplementationType) as IFilter;
                constantScore = new ConstantScoreFilter(filter);
            }
            else 
            {
                throw new Exception("ConstantScore expects a filter or query.");
            }

            constantScore.Boost = fieldDict.GetDouble(QuerySerializer._BOOST, QuerySerializer._BOOST_DEFAULT);
            constantScore.QueryName = fieldDict.GetStringOrDefault(QuerySerializer._QUERY_NAME);
            return constantScore;
        }   
 public void FAIL_CreateQuery_SearchPiece()
 {
     try
     {
         ConstantScoreQuery query = new ConstantScoreQuery(null);
         Assert.Fail();
     }
     catch (ArgumentException argEx)
     {
         Assert.AreEqual("searchPiece", argEx.ParamName);
     }
 }
        public void PASS_CreateQuery()
        {
            ConstantScoreQuery query = new ConstantScoreQuery(new TermQuery("field", "value"))
            {
                Boost = 1.2
            };

            Assert.IsNotNull(query);
            Assert.AreEqual(1.2, query.Boost);
            Assert.IsTrue(query.SearchPiece is TermQuery);
            Assert.AreEqual("field", (query.SearchPiece as TermQuery).Field);
            Assert.AreEqual("value", (query.SearchPiece as TermQuery).Value);
        }
        public void PASS_Serialize()
        {
            ConstantScoreQuery query = new ConstantScoreQuery(new TermQuery("field", "value"))
            {
                Boost = 1.2
            };

            string json = JsonConvert.SerializeObject(query);

            Assert.IsNotNull(json);

            string expectedJson = "{\"constant_score\":{\"query\":{\"term\":{\"field\":\"value\"}},\"boost\":1.2}}";
            Assert.AreEqual(expectedJson, json);
        }