Esempio n. 1
0
        public ProductsOptions(object json, SonicElasticStoreOptions options, int?id = null, int?skip = null, int?take = null)
        {
            _json          = json;
            ElasticOptions = options ?? new SonicElasticStoreOptions();

            Filters     = new List <IElasticFilter>();
            DataFilters = new Dictionary <string, string>();

            if (!(json is JObject jobj))
            {
                return;
            }

            Id              = id ?? 0;
            Page            = (decimal?)jobj.SelectToken(PAGE);
            PerPage         = (decimal?)jobj.SelectToken(PER_PAGE);
            Skip            = skip ?? (decimal?)jobj.SelectToken(SKIP);
            Take            = take ?? (decimal?)jobj.SelectToken(TAKE);
            CacheForSeconds = (decimal?)jobj.SelectToken(CACHE_FOR_SECONDS) ?? 0;

            PropertiesFilter = JTokenToStringArray(jobj.SelectToken(FIELDS));
            DisableOr        = JTokenToStringArray(jobj.SelectToken(DISABLE_OR));
            DisableNot       = JTokenToStringArray(jobj.SelectToken(DISABLE_NOT));
            DisableLike      = JTokenToStringArray(jobj.SelectToken(DISABLE_LIKE));

            Sort           = (string)jobj.SelectToken(SORT);
            OrderDirection = (string)jobj.SelectToken(ORDER);
            Filters        = GetFilters(jobj, Id);
            DataFilters    = GetDataFilters(jobj);
        }
Esempio n. 2
0
        private static string GetParameterName(string key, SonicElasticStoreOptions options, out bool isDisjunction)
        {
            isDisjunction = false;

            if (key.StartsWith(options.DisjunctionMark))
            {
                isDisjunction = true;
                key           = key.Substring(options.DisjunctionMark.Length);
            }

            while (key.StartsWith(options.EscapeCharacter))
            {
                key = key.Substring(options.EscapeCharacter.Length);
            }

            return(key);
        }
Esempio n. 3
0
 public ProductOptionsBinder(SonicElasticStoreOptions options)
 {
     _options = options;
 }
Esempio n. 4
0
        public static IElasticFilter CreateFilter(KeyValuePair <string, StringValues> pair, SonicElasticStoreOptions options)
        {
            var name = GetParameterName(pair.Key, options, out var isDisjunction);

            if (name == "q")
            {
                return(new QueryFilter()
                {
                    Query = pair.Value,
                    IsDisjunction = isDisjunction
                });
            }

            var match = RangeFilterRegex.Match(pair.Value);

            if (match.Success)
            {
                return(new RangeFilter
                {
                    Name = name,
                    Floor = match.Groups[1].Value,
                    Ceiling = match.Groups[2].Value,
                    IsDisjunction = isDisjunction
                });
            }

            return(new SimpleFilter
            {
                Name = name,
                Values = pair.Value,
                IsDisjunction = isDisjunction
            });
        }