コード例 #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            IEnumerable<Dictionary<string, object>> queries = null;
            if (reader.TokenType == JsonToken.StartArray)
            {
                queries = serializer.Deserialize<IEnumerable<Dictionary<string, object>>>(reader);
            }
            else
            {
                queries = new List<Dictionary<string, object>>()
                {
                    serializer.Deserialize<Dictionary<string, object>>(reader)
                };
            }

            List<RescoreQuery> rescoreQueries = new List<RescoreQuery>();
            foreach (Dictionary<string, object> rescoreDict in queries)
            {
                Dictionary<string, object> queryDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(rescoreDict.GetString(_QUERY));
                RescoreQuery rescoreQuery = new RescoreQuery(JsonConvert.DeserializeObject<IQuery>(queryDict.GetString(_RESCORE_QUERY)));

                rescoreQuery.QueryWeight = queryDict.GetDouble(_QUERY_WEIGHT, _QUERY_WEIGHT_DEFAULT);
                rescoreQuery.RescoreQueryWeight = queryDict.GetDouble(_RESCORE_QUERY_WEIGHT, _RESCORE_QUERY_WEIGHT_DEFAULT);
                rescoreQuery.ScoreMode = ScoreModeEnum.Find(queryDict.GetString(_SCORE_MODE, _SCORE_MODE_DEFAULT.ToString()));
                rescoreQuery.WindowSize = rescoreDict.GetInt32OrNull(_WINDOW_SIZE);

                rescoreQueries.Add(rescoreQuery);
            }

            return new Rescore(rescoreQueries);
        }
コード例 #2
0
        private Dictionary<string, object> SerializeRescore(RescoreQuery rescoreQuery)
        {
            Dictionary<string, object> queryDict = new Dictionary<string, object>();
            queryDict.AddObject(_SCORE_MODE, rescoreQuery.ScoreMode.ToString(), _SCORE_MODE_DEFAULT.ToString());
            queryDict.Add(_RESCORE_QUERY, rescoreQuery.Query);
            queryDict.AddObject(_QUERY_WEIGHT, rescoreQuery.QueryWeight, _QUERY_WEIGHT_DEFAULT);
            queryDict.AddObject(_RESCORE_QUERY_WEIGHT, rescoreQuery.RescoreQueryWeight, _RESCORE_QUERY_WEIGHT_DEFAULT);

            Dictionary<string, object> rescoreDict = new Dictionary<string, object>();
            rescoreDict.AddObject(_WINDOW_SIZE, rescoreQuery.WindowSize);
            rescoreDict.Add(_QUERY, queryDict);

            return rescoreDict;
        }