public void PASS_CreateRequest()
        {
            MoreLikeThisFieldQuery query = new MoreLikeThisFieldQuery("field", "value");

            Assert.IsNotNull(query);
            Assert.AreEqual("field", query.Fields.First());
            Assert.AreEqual("value", query.Query);
        }
        public void PASS_Serialize()
        {
            MoreLikeThisFieldQuery query = new MoreLikeThisFieldQuery("field", "value");

            string json = JsonConvert.SerializeObject(query);
            Assert.IsNotNull(json);
            string expectedJson = "{\"more_like_this_field\":{\"field\":{\"like_text\":\"value\"}}}";
            Assert.AreEqual(expectedJson, json);
        }
 public void FAIL_CreateRequest_Query()
 {
     try
     {
         MoreLikeThisFieldQuery query = new MoreLikeThisFieldQuery("field", null);
         Assert.Fail();
     }
     catch (ArgumentNullException ex)
     {
         Assert.AreEqual("query", ex.ParamName);
     }
 }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            Dictionary<string, object> fieldDict = serializer.Deserialize<Dictionary<string, object>>(reader);
            QueryTypeEnum queryType = QueryTypeEnum.FuzzyLikeThis;
            queryType = QueryTypeEnum.Find(fieldDict.First().Key);

            MoreLikeThisBase query = null;

            if (queryType != null)
            {
                fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict.First().Value.ToString());
            }

            if (fieldDict.ContainsKey(_LIKE_TEXT))
            {
                query = new MoreLikeThisQuery();
            }
            else
            {
                query = new MoreLikeThisFieldQuery();
                query.Fields = new List<string>() { fieldDict.First().Key };
                fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict.First().Value.ToString());
            }

            query.Query = fieldDict.GetString(_LIKE_TEXT);
            query.PercentageTermsToMatch = fieldDict.GetDouble(_PERCENTAGE_TERMS_TO_MATCH, _PERCENTAGE_TERMS_TO_MATCH_DEFAULT);
            query.MinimumTermFrequency = fieldDict.GetInt32(_MINIMUM_TERM_FREQUENCY, _MINIMUM_TERM_FREQUENCY_DEFAULT);
            query.MaximumQueryTerms = fieldDict.GetInt32(_MAXIMUM_QUERY_TERMS, _MAXIMUM_QUERY_TERMS_DEFAULT);
            query.Analyzer = fieldDict.GetStringOrDefault(_ANALYZER);
            query.Boost = fieldDict.GetDouble(QuerySerializer._BOOST, QuerySerializer._BOOST_DEFAULT);
            query.BoostTerms = fieldDict.GetInt32(_BOOST_TERMS, _BOOST_TERMS_DEFAULT);
            query.MaximumDocumentFrequency = fieldDict.GetInt32OrNull(_MAXIMUM_DOCUMENT_FREQUENCY);
            query.MaximumWordLength = fieldDict.GetInt32(_MAXIMUM_WORD_LENGTH, _MAXIMUM_WORD_LENGTH_DEFAULT);
            query.MinimumDocumentFrequency = fieldDict.GetInt32(_MINIMUM_DOCUMENT_FREQUENCY, _MINIMUM_DOCUMENT_FREQUENCY_DEFAULT);
            query.MinimumWordLength = fieldDict.GetInt32(_MINIMUM_WORD_LENGTH, _MINIMUM_WORD_LENGTH_DEFAULT);
            query.QueryName = fieldDict.GetStringOrDefault(QuerySerializer._QUERY_NAME);

            if (fieldDict.ContainsKey(_FIELDS))
                query.Fields = JsonConvert.DeserializeObject<IEnumerable<string>>(fieldDict[_FIELDS].ToString());

            if(fieldDict.ContainsKey(_STOP_WORDS))
                query.StopWords = JsonConvert.DeserializeObject<IEnumerable<string>>(fieldDict[_STOP_WORDS].ToString());

            return query;
        }