Example #1
0
 internal static void DeserializeFacetInfo(FacetBase facet, Dictionary<string, object> facetDict)
 {
     if (facetDict.ContainsKey(_FACET_FILTER))
         facet.FacetFilter = JsonConvert.DeserializeObject<IFilter>(facetDict.GetString(_FACET_FILTER));
     facet.IsScopeGlobal = facetDict.GetBool(_GLOBAL, _GLOBAL_DEFAULT);
     facet.NestedObject = facetDict.GetStringOrDefault(_NESTED);
     facet.Size = facetDict.GetInt32(_SIZE, _SIZE_DEFAULT);
 }
        internal static void Deserialize(DocumentPropertyBase prop, Dictionary<string, object> fieldDict)
        {
            if (!fieldDict.Any())
                return;

            MappingBase.Deserialize(prop, fieldDict);
            prop.IncludeInAll = fieldDict.GetBool(_INCLUDE_IN_ALL, _INCLUDE_IN_ALL_DEFAULT);
            prop.IndexName = fieldDict.GetStringOrDefault(_INDEX_NAME);
            prop.PropertyType = PropertyTypeEnum.Find(fieldDict.GetString(_TYPE, _PROPERTY_TYPE_DEFAULT.ToString()));
        }
Example #3
0
File: Order.cs Project: abel/sinan
        public static Order CreateShipment(Dictionary<string, string> querise)
        {
            Order log = new Order();
            log.Created = DateTime.UtcNow;
            log.amt = int.Parse(querise.GetStringOrDefault("amt"));
            log.billno = querise.GetStringOrDefault("billno");
            log.openid = querise.GetStringOrDefault("openid");
            log.payitem = querise.GetStringOrDefault("payitem");
            log.version = querise.GetStringOrDefault("version") ?? "v3";

            int providetype;
            if (int.TryParse(querise.GetStringOrDefault("providetype"), out providetype))
            {
                log.providetype = providetype;
            }

            log.ppc = querise.GetStringOrDefault("pubacct_payamt_coins");
            log.sig = querise.GetStringOrDefault("sig");
            log.token = querise.GetStringOrDefault("token");

            long ts;
            if (long.TryParse(querise.GetStringOrDefault("ts"), out ts))
            {
                log.ts = ts;
            }

            string zone = querise.GetStringOrDefault("zoneid");
            if (!string.IsNullOrEmpty(zone))
            {
                if (zone[0] == 'S' || zone[0] == 's')
                {
                    log.zoneid = int.Parse(zone.Substring(1));
                }
                else
                {
                    log.zoneid = int.Parse(zone);
                }
            }
            return log;
        }
Example #4
0
 internal static void DeserializeBaseValues(IFilter filter, bool cacheDefault, Dictionary<string, object> fieldDict)
 {
     filter.Cache = fieldDict.GetBool(_CACHE, cacheDefault);
     filter.CacheKey = fieldDict.GetStringOrDefault(_CACHE_KEY);
     filter.FilterName = fieldDict.GetStringOrDefault(_FILTER_NAME);
 }
Example #5
0
 private void ReadFieldsDict(Dictionary<string, object> fieldsDict, MatchQueryBase matchQuery)
 {
     matchQuery.Analyzer = fieldsDict.GetStringOrDefault(_ANALYZER);
     matchQuery.CutOffFrequency = fieldsDict.GetDouble(_CUTOFF_FREQUENCY, _CUTOFF_FREQUENCY_DEFAULT);
     matchQuery.Fuzziness = fieldsDict.GetDouble(_FUZZINESS, _FUZZINESS_DEFAULT);
     matchQuery.IsLenient = fieldsDict.GetBool(_LENIENT, _LENIENT_DEFAULT);
     matchQuery.MaximumExpansions = fieldsDict.GetInt32OrNull(_MAX_EXPANSIONS);
     matchQuery.MinimumShouldMatch = fieldsDict.GetInt32(_MINIMUM_SHOULD_MATCH, _MINIMUM_SHOULD_MATCH_DEFAULT);
     matchQuery.Operator = OperatorEnum.Find(fieldsDict.GetString(_OPERATOR, _OPERATOR_DEFAULT.ToString()));
     matchQuery.PrefixLength = fieldsDict.GetInt32(_PREFIX_LENGTH, _PREFIX_LENGTH_DEFAULT);
     matchQuery.RewriteMethod = RewriteMethodsEnum.Find(fieldsDict.GetString(_REWRITE, "not a real object"));
     matchQuery.ZeroTerm = ZeroTermsEnum.Find(fieldsDict.GetString(_ZERO_TERMS_QUERY, _ZERO_TERMS_QUERY_DEFAULT.ToString()));
     matchQuery.QueryName = fieldsDict.GetStringOrDefault(QuerySerializer._QUERY_NAME);
 }
Example #6
0
        private static RangeQueryBase BuildRangeQuery(string fieldName, Dictionary<string, object> fieldDict)
        {
            object value = fieldDict.First(x => x.Key != QuerySerializer._BOOST).Value;

            RangeQueryBase query = null;

            if (value is Int32 || value is Int64)
            {
                query = new IntegerRangeQuery(fieldName,
                    fieldDict.GetInt64OrNull(_GREATER_THAN),
                    fieldDict.GetInt64OrNull(_LESS_THAN),
                    fieldDict.GetInt64OrNull(_GREATER_THAN_OR_EQUAL_TO),
                    fieldDict.GetInt64OrNull(_LESS_THAN_OR_EQUAL_TO));
            }
            else if (value is Double || value is float)
            {
                query = new DoubleRangeQuery(fieldName,
                    fieldDict.GetDoubleOrNull(_GREATER_THAN),
                    fieldDict.GetDoubleOrNull(_LESS_THAN),
                    fieldDict.GetDoubleOrNull(_GREATER_THAN_OR_EQUAL_TO),
                    fieldDict.GetDoubleOrNull(_LESS_THAN_OR_EQUAL_TO));
            }
            else
            {
                try
                {
                    DateTime.Parse(value.ToString());
                    query = new DateTimeRangeQuery(fieldName,
                        fieldDict.GetDateTimeOrNull(_GREATER_THAN),
                        fieldDict.GetDateTimeOrNull(_LESS_THAN),
                        fieldDict.GetDateTimeOrNull(_GREATER_THAN_OR_EQUAL_TO),
                        fieldDict.GetDateTimeOrNull(_LESS_THAN_OR_EQUAL_TO));
                }
                catch
                {
                    query = new StringRangeQuery(fieldName,
                        fieldDict.GetStringOrDefault(_GREATER_THAN),
                        fieldDict.GetStringOrDefault(_LESS_THAN),
                        fieldDict.GetStringOrDefault(_GREATER_THAN_OR_EQUAL_TO),
                        fieldDict.GetStringOrDefault(_LESS_THAN_OR_EQUAL_TO));
                }
            }

            query.QueryName = fieldDict.GetStringOrDefault(QuerySerializer._QUERY_NAME);

            return query;
        }
Example #7
0
        private FuzzyQueryBase BuildFuzzyQuery(string fieldName, Dictionary<string, object> fieldDict)
        {
            object value = fieldDict[_VALUE];
            object fuzziness = null;
            if (fieldDict.ContainsKey(_FUZZINESS))
                fuzziness = fieldDict[_FUZZINESS];

            FuzzyQueryBase query = null;
            if (IsDateTime(value))
            {
                if(fuzziness != null)
                    query = new FuzzyDateQuery(fieldName, DateTime.Parse(value.ToString()), new TimeValue(fuzziness.ToString()).TimeSpan);
                else
                    query = new FuzzyDateQuery(fieldName, DateTime.Parse(value.ToString()));
            }
            else if (IsNumeric(value))
            {
                bool isInteger = false;
                if (value is Int64 || value is Int32)
                    isInteger = true;

                if (fuzziness != null && isInteger)
                {
                    if (isInteger)
                        query = new FuzzyNumberQuery(fieldName, (Int64)value, (Int64)fuzziness);
                    else
                        query = new FuzzyNumberQuery(fieldName, (Double)value, (Double)fuzziness);
                }
                else
                {
                    if (isInteger)
                        query = new FuzzyNumberQuery(fieldName, (Int64)value);
                    else
                        query = new FuzzyNumberQuery(fieldName, (Double)value);
                }
            }
            else
            {
                if (fuzziness != null)
                    query = new FuzzyStringQuery(fieldName, value.ToString(), Int32.Parse(fuzziness.ToString()));
                else
                    query = new FuzzyStringQuery(fieldName, value.ToString());
            }

            query.Boost = fieldDict.GetDouble(QuerySerializer._BOOST, QuerySerializer._BOOST_DEFAULT);
            query.MaximumExpansions = fieldDict.GetInt32(_MAXIMUM_EXPANSIONS, _MAXIMUM_EXPANSIONS_DEFAULT);
            query.PrefixLength = fieldDict.GetInt32(_PREFIX_LENGTH, _PREFIX_LENGTH_DEFAULT);
            query.QueryName = fieldDict.GetStringOrDefault(QuerySerializer._QUERY_NAME);
            return query;
        }
Example #8
0
        private RangeBucket DeserializeRangeBucket(Dictionary<string, object> bucketDict)
        {
            RangeBucket bucket = new RangeBucket();
            if (bucketDict.ContainsKey(_GREATER_THAN))
                bucket.GreaterThan = bucketDict[_GREATER_THAN];
            if (bucketDict.ContainsKey(_LESS_THAN))
                bucket.LessThan = bucketDict[_LESS_THAN];
            if (bucketDict.ContainsKey(_GREATER_THAN_OR_EQUAL_TO))
                bucket.GreaterThanOrEqualTo = bucketDict[_GREATER_THAN_OR_EQUAL_TO];
            if (bucketDict.ContainsKey(_LESS_THAN_OR_EQUAL_TO))
                bucket.LessThanOrEqualTo = bucketDict[_LESS_THAN_OR_EQUAL_TO];

            bucket.Key = bucketDict.GetStringOrDefault(_RANGE_KEY);

            return bucket;
        }
Example #9
0
        private static RangeFilterBase BuildRangeFilter(string fieldName, Dictionary<string, object> fieldDict)
        {
            object value = fieldDict.First().Value;

            if (value is Int32 || value is Int64)
            {
                return new IntegerRangeFilter(fieldName,
                    fieldDict.GetInt64OrNull(_GREATER_THAN),
                    fieldDict.GetInt64OrNull(_LESS_THAN),
                    fieldDict.GetInt64OrNull(_GREATER_THAN_OR_EQUAL_TO),
                    fieldDict.GetInt64OrNull(_LESS_THAN_OR_EQUAL_TO));
            }

            if (value is Double || value is float)
            {
                return new DoubleRangeFilter(fieldName,
                    fieldDict.GetDoubleOrNull(_GREATER_THAN),
                    fieldDict.GetDoubleOrNull(_LESS_THAN),
                    fieldDict.GetDoubleOrNull(_GREATER_THAN_OR_EQUAL_TO),
                    fieldDict.GetDoubleOrNull(_LESS_THAN_OR_EQUAL_TO));
            }

            try
            {
                DateTime.Parse(value.ToString());
                return new DateTimeRangeFilter(fieldName,
                    fieldDict.GetDateTimeOrNull(_GREATER_THAN),
                    fieldDict.GetDateTimeOrNull(_LESS_THAN),
                    fieldDict.GetDateTimeOrNull(_GREATER_THAN_OR_EQUAL_TO),
                    fieldDict.GetDateTimeOrNull(_LESS_THAN_OR_EQUAL_TO));
            }
            catch
            {
                return new StringRangeFilter(fieldName,
                    fieldDict.GetStringOrDefault(_GREATER_THAN),
                    fieldDict.GetStringOrDefault(_LESS_THAN),
                    fieldDict.GetStringOrDefault(_GREATER_THAN_OR_EQUAL_TO),
                    fieldDict.GetStringOrDefault(_LESS_THAN_OR_EQUAL_TO));
            }
        }
Example #10
0
        internal static PropertyAnalyzer Deserialize(Dictionary<string, object> fieldDict)
        {
            if (fieldDict == null || !fieldDict.Any())
                return null;

            PropertyAnalyzer propertyAnalyzer = null;
            if (fieldDict.ContainsKey(_ANALYZER))
            {
                propertyAnalyzer = new PropertyAnalyzer(GetAnalyzer(fieldDict.GetString(_ANALYZER)));
            }
            else if (fieldDict.ContainsKey(_INDEX_ANALYZER))
            {
                IAnalyzer searchAnalyzer = null;
                try 
                { 
                    searchAnalyzer = GetAnalyzer(fieldDict.GetStringOrDefault(_SEARCH_ANALYZER));
                }
                catch{}

                propertyAnalyzer = new PropertyAnalyzer(
                    GetAnalyzer(fieldDict.GetString(_INDEX_ANALYZER)),
                    searchAnalyzer);
            }

            return propertyAnalyzer;
        }