コード例 #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            Dictionary<string, object> filterDict = serializer.Deserialize<Dictionary<string, object>>(reader);
            Dictionary<string, object> fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(filterDict.First().Value.ToString());

            string filterName = filterDict.First().Key;
            SynonymTokenFilter filter = null;
            if (fieldDict.ContainsKey(_SYNONYMS))
            {
                filter = new SynonymTokenFilter(filterName, JsonConvert.DeserializeObject<IEnumerable<string>>(fieldDict.GetString(_SYNONYMS)));
            }
            else if (fieldDict.ContainsKey(_SYNONYMS_PATH))
            {
                filter = new SynonymTokenFilter(filterName, fieldDict.GetString(_SYNONYMS_PATH));
            }
            else
            {
                throw new RequiredPropertyMissingException(_SYNONYMS + "/" + _SYNONYMS_PATH);
            }

            TokenFilterBase.Deserialize(filter, fieldDict);

            filter.Expand = fieldDict.GetBool(_EXPAND, SynonymTokenFilter._EXPAND_DEFAULT);
            filter.IgnoreCase = fieldDict.GetBool(_IGNORE_CASE, SynonymTokenFilter._INGORE_CASE_DEFAULT);

            return filter;
        }
コード例 #2
0
        public void PASS_Create()
        {
            SynonymTokenFilter filter = new SynonymTokenFilter("name", "path")
            {
                Version = 2.4
            };

            Assert.IsNotNull(filter);
            Assert.AreEqual("name", filter.Name);
            Assert.AreEqual(2.4, filter.Version);
            Assert.AreEqual("path", filter.SynonymsPath);
        }
コード例 #3
0
        public void PASS_Serialize()
        {
            SynonymTokenFilter filter = new SynonymTokenFilter("name", "path")
            {
                Version = 2.4
            };

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

            string expectedJson = "{\"name\":{\"type\":\"synonym\",\"version\":2.4,\"synonyms_path\":\"path\"}}";
            Assert.AreEqual(expectedJson, json);
        }