コード例 #1
0
        public CatalogSearchQuery PriceBetween(
            decimal?fromPrice,
            decimal?toPrice,
            bool?includeFrom = null,
            bool?includeTo   = null)
        {
            if (fromPrice == null && toPrice == null)
            {
                return(this);
            }

            Guard.NotEmpty(CurrencyCode, nameof(CurrencyCode));

            var fieldName = "price_c-" + CurrencyCode.EmptyNull().ToLower();

            if (fromPrice.HasValue && toPrice.HasValue && fromPrice == toPrice)
            {
                var forbidden = includeFrom.HasValue && includeTo.HasValue && !includeFrom.Value && !includeTo.Value;

                return(WithFilter(SearchFilter.ByField(fieldName, decimal.ToDouble(fromPrice.Value)).Mandatory(!forbidden).ExactMatch().NotAnalyzed()));
            }
            else
            {
                var filter = SearchFilter.ByRange(fieldName,
                                                  fromPrice.HasValue ? decimal.ToDouble(fromPrice.Value) : null,
                                                  toPrice.HasValue ? decimal.ToDouble(toPrice.Value) : null,
                                                  includeFrom ?? fromPrice.HasValue,
                                                  includeTo ?? toPrice.HasValue);

                return(WithFilter(filter.Mandatory().ExactMatch().NotAnalyzed()));
            }
        }
コード例 #2
0
        public CatalogSearchQuery PriceBetween(decimal?fromPrice, decimal?toPrice)
        {
            if (fromPrice == null && toPrice == null)
            {
                return(this);
            }

            Guard.NotEmpty(CurrencyCode, nameof(CurrencyCode));

            var fieldName = "price_c-" + CurrencyCode.EmptyNull().ToLower();

            return(WithFilter(SearchFilter.ByRange(fieldName,
                                                   fromPrice.HasValue ? decimal.ToDouble(fromPrice.Value) : (double?)null,
                                                   toPrice.HasValue ? decimal.ToDouble(toPrice.Value) : (double?)null,
                                                   fromPrice.HasValue,
                                                   toPrice.HasValue).Mandatory().ExactMatch().NotAnalyzed()
                              ));
        }