Пример #1
0
        public ConstantScoreQueryDescriptor <T> Filter(Action <FilterDescriptor <T> > filterSelector)
        {
            filterSelector.ThrowIfNull("filterSelector");
            this._Query = null;
            var filter = new FilterDescriptor <T>();

            filterSelector(filter);

            this._Filter = filter;
            return(this);
        }
Пример #2
0
        public void Or(params Action <FilterDescriptor <T> >[] filters)
        {
            var descriptors = new List <FilterDescriptor <T> >();

            foreach (var selector in filters)
            {
                var filter = new FilterDescriptor <T>();
                selector(filter);
                descriptors.Add(filter);
            }
            this.SetDictionary("filters", descriptors, (d) => this.OrFilter = d);
        }
        public IndicesFilterDescriptor <T> NoMatchFilter <K>(Func <FilterDescriptor <K>, IFilterContainer> filterSelector) where K : class
        {
            var qd = new FilterDescriptor <K>();
            var q  = filterSelector(qd);

            if (q.IsConditionless)
            {
                return(this);
            }

            ((IIndicesFilter)this).NoMatchFilter = q;
            return(this);
        }
Пример #4
0
        public BoolFilterDescriptor <T> Should(params Action <FilterDescriptor <T> >[] filters)
        {
            var descriptors = new List <FilterDescriptor <T> >();

            foreach (var selector in filters)
            {
                var filter = new FilterDescriptor <T>();
                selector(filter);
                descriptors.Add(filter);
            }
            this._ShouldFilters = descriptors;
            return(this);
        }
Пример #5
0
        public BoolFilterDescriptor <T> Should(params Func <FilterDescriptor <T>, BaseFilter>[] filters)
        {
            var descriptors = new List <BaseFilter>();

            foreach (var selector in filters)
            {
                var filter = new FilterDescriptor <T>();
                var f      = selector(filter);
                descriptors.Add(f);
            }
            this._ShouldFilters = descriptors;
            return(this);
        }
        public TermFacetDescriptor <T> FacetFilter(
            Func <FilterDescriptor <T>, BaseFilter> facetFilter
            )
        {
            var filter = new FilterDescriptor <T>();
            var f      = facetFilter(filter);

            if (f.IsConditionless)
            {
                f = null;
            }
            this._FacetFilter = f;
            return(this);
        }
        public IndicesFilterDescriptor <T> Filter(Func <FilterDescriptor <T>, FilterContainer> filterSelector)
        {
            var qd = new FilterDescriptor <T>();
            var q  = filterSelector(qd);

            if (q.IsConditionless)
            {
                return(this);
            }


            ((IIndicesFilter)this).Filter = q;
            return(this);
        }
Пример #8
0
        /// <summary>
        /// A filter that filters out matched documents using a query.
        /// This filter is more performant then bool filter.
        /// </summary>
        public BaseFilter Not(Func <FilterDescriptor <T>, BaseFilter> selector)
        {
            var        filter = new FilterDescriptor <T>();
            BaseFilter bf     = filter;

            if (selector != null)
            {
                bf = selector(filter);
            }

            return(this.SetDictionary("not", "filter", bf, (d, b) =>
            {
                b.NotFilter = d;
            }));
        }
Пример #9
0
        public BoolFilterDescriptor <T> MustNot(params Func <FilterDescriptor <T>, BaseFilter>[] filters)
        {
            var descriptors = new List <BaseFilter>();

            foreach (var selector in filters)
            {
                var filter = new FilterDescriptor <T>();
                var f      = selector(filter);
                if (f.IsConditionless)
                {
                    continue;
                }
                descriptors.Add(f);
            }
            this._MustNotFilters = descriptors;
            return(this);
        }
Пример #10
0
        public BoolFilterDescriptor <T> Must(params Func <FilterDescriptor <T>, FilterContainer>[] filters)
        {
            var descriptors = new List <FilterContainer>();

            foreach (var selector in filters)
            {
                var filter = new FilterDescriptor <T>();
                var f      = selector(filter);
                if (f.IsConditionless)
                {
                    continue;
                }
                descriptors.Add(f);
            }
            ((IBoolFilter)this).Must = descriptors;
            return(this);
        }
Пример #11
0
        /// <summary>
        /// A filter that filters out matched documents using a query.
        /// This filter is more performant then bool filter.
        /// </summary>
        public FilterContainer Not(Func <FilterDescriptor <T>, FilterContainer> selector)
        {
            var notFilter = new NotFilterDescriptor();

            var filter = new FilterDescriptor <T>()
            {
                IsConditionless = true
            };
            FilterContainer bf = filter;

            if (selector != null)
            {
                bf = selector(filter);
            }

            ((INotFilter)notFilter).Filter = bf;
            return(this.New(notFilter, f => f.Not = notFilter));
        }
Пример #12
0
        /// <summary>
        /// A filter facet (not to be confused with a facet filter) allows you to return a count of the h
        /// its matching the filter. The filter itself can be expressed using the Query DSL.
        /// Note, filter facet filters are faster than query facet when using native filters (non query wrapper ones).
        /// </summary>
        public SearchDescriptor <T> FacetFilter(string name, Action <FilterDescriptor <T> > querySelector)
        {
            name.ThrowIfNullOrEmpty("name");
            querySelector.ThrowIfNull("query");
            if (this._Facets == null)
            {
                this._Facets = new Dictionary <string, FacetDescriptorsBucket <T> >();
            }

            var filter = new FilterDescriptor <T>();

            querySelector(filter);
            this._Facets.Add(name, new FacetDescriptorsBucket <T> {
                Filter = filter
            });

            return(this);
        }
Пример #13
0
        /// <summary>
        /// A filter facet (not to be confused with a facet filter) allows you to return a count of the h
        /// its matching the filter. The filter itself can be expressed using the Query DSL.
        /// Note, filter facet filters are faster than query facet when using native filters (non query wrapper ones).
        /// </summary>
        public SearchDescriptor <T> FacetFilter(string name, Func <FilterDescriptor <T>, BaseFilter> filterSelector)
        {
            name.ThrowIfNullOrEmpty("name");
            filterSelector.ThrowIfNull("filterSelector");

            if (this._Facets == null)
            {
                this._Facets = new Dictionary <PropertyPathMarker, FacetDescriptorsBucket <T> >();
            }

            var filter = new FilterDescriptor <T>();
            var f      = filterSelector(filter);

            this._Facets.Add(name, new FacetDescriptorsBucket <T> {
                Filter = f
            });

            return(this);
        }
Пример #14
0
        /// <summary>
        /// A filter facet (not to be confused with a facet filter) allows you to return a count of the h
        /// its matching the filter. The filter itself can be expressed using the Query DSL.
        /// Note, filter facet filters are faster than query facet when using native filters (non query wrapper ones).
        /// </summary>
        public SearchDescriptor <T> FacetFilter(string name, Func <FilterDescriptor <T>, FilterContainer> filterSelector)
        {
            name.ThrowIfNullOrEmpty("name");
            filterSelector.ThrowIfNull("filterSelector");

            if (Self.Facets == null)
            {
                Self.Facets = new Dictionary <PropertyPathMarker, IFacetContainer>();
            }

            var filter = new FilterDescriptor <T>();
            var f      = filterSelector(filter);

            Self.Facets.Add(name, new FacetContainer {
                Filter = f
            });

            return(this);
        }
        /// <summary>
        /// Filter search using a filter descriptor lambda
        /// </summary>
        public PercolateCountDescriptor <T> Filter(Func <FilterDescriptor <T>, FilterContainer> filter)
        {
            filter.ThrowIfNull("filter");
            var f = new FilterDescriptor <T>();

            var bf = filter(f);

            if (bf == null)
            {
                return(this);
            }
            if (bf.IsConditionless)
            {
                return(this);
            }


            Self.Filter = bf;
            return(this);
        }
Пример #16
0
        private FilterDescriptor <T> New(FilterBase filter, Action <FilterDescriptor <T> > fillProperty)
        {
            if (filter.IsConditionless && !this.IsVerbatim)
            {
                return(CreateConditionlessFilterDescriptor(filter));
            }

            this.SetCacheAndName(filter);

            var f = new FilterDescriptor <T> {
                IsStrict = this.IsStrict, IsVerbatim = this.IsVerbatim
            };

            if (fillProperty != null)
            {
                fillProperty(f);
            }

            this.ResetCache();
            return(f);
        }
Пример #17
0
        /// <summary>
        /// Filter search using a filter descriptor lambda
        /// </summary>
        public SearchDescriptor <T> Filter(Func <FilterDescriptor <T>, BaseFilter> filter)
        {
            filter.ThrowIfNull("filter");
            var f = new FilterDescriptor <T>().Strict(this._Strict);

            var bf = filter(f);

            if (this._Strict && bf.IsConditionless)
            {
                throw new DslException("Filter resulted in a conditionless filter:\n{0}".F(JsonConvert.SerializeObject(bf, Formatting.Indented)));
            }

            else if (bf.IsConditionless)
            {
                return(this);
            }


            this._Filter = bf;
            return(this);
        }
Пример #18
0
        private FilterDescriptor <T> CreateConditionlessFilterDescriptor(IFilter filter, string type = null)
        {
            var self = Self;

            if (self.IsStrict && !self.IsVerbatim)
            {
                throw new DslException("Filter resulted in a conditionless '{1}' filter (json by approx):\n{0}"
                                       .F(
                                           JsonConvert.SerializeObject(this, Formatting.Indented, new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                })
                                           , type ?? filter.GetType().Name.Replace("Descriptor", "").Replace("`1", "")
                                           )
                                       );
            }
            var f = new FilterDescriptor <T>();

            f.Self.IsStrict   = self.IsStrict;
            f.Self.IsVerbatim = self.IsVerbatim;
            f.IsConditionless = true;
            return(f);
        }
Пример #19
0
        private FilterDescriptor <T> New(IFilter filter, Action <IFilterContainer> fillProperty)
        {
            var self = Self;

            if (filter.IsConditionless && !self.IsVerbatim)
            {
                this.ResetCache();
                return(CreateConditionlessFilterDescriptor(filter));
            }

            this.SetCacheAndName(filter);
            var f = new FilterDescriptor <T>();

            f.Self.IsStrict   = self.IsStrict;
            f.Self.IsVerbatim = self.IsVerbatim;

            if (fillProperty != null)
            {
                fillProperty(f);
            }

            this.ResetCache();
            return(f);
        }
Пример #20
0
        private BaseFilter SetDictionary(
            string type,
            PropertyPathMarker key,
            object value,
            Action <Dictionary <PropertyPathMarker, object>, FilterDescriptor <T> > setter
            )
        {
            setter.ThrowIfNull("setter");
            var dictionary = new Dictionary <PropertyPathMarker, object>();

            if (key.IsConditionless())
            {
                return(CreateConditionlessFilterDescriptor(dictionary, type));
            }

            dictionary.Add(key, value);
            if (this._Cache.HasValue)
            {
                dictionary.Add("_cache", this._Cache);
            }
            if (!string.IsNullOrWhiteSpace(this._Name))
            {
                dictionary.Add("_name", this._Name);
            }
            if (!string.IsNullOrWhiteSpace(this._CacheKey))
            {
                dictionary.Add("_cache_key", this._CacheKey);
            }

            this.ResetCache();

            var bucket = new FilterDescriptor <T> {
                IsStrict = this.IsStrict, IsVerbatim = this.IsVerbatim
            };

            setter(dictionary, bucket);
            if (this.IsVerbatim)
            {
                return(bucket);
            }

            //find out if we are conditionless

            if (value == null)
            {
                return(CreateConditionlessFilterDescriptor(dictionary, type));
            }
            else if (value is string)
            {
                if (string.IsNullOrEmpty(value.ToString()))
                {
                    return(CreateConditionlessFilterDescriptor(value, type));
                }
            }
            else if (value is IEnumerable <BaseFilter> )
            {
                var l           = (IEnumerable <object>)value;
                var baseFilters = l.OfType <BaseFilter>().ToList();
                var allBaseFiltersConditionless = baseFilters.All(b => b.IsConditionless);
                if (!baseFilters.HasAny() || allBaseFiltersConditionless)
                {
                    return(CreateConditionlessFilterDescriptor(dictionary, type));
                }
            }
            else if (value is IEnumerable <string> )
            {
                var l       = (IEnumerable <string>)value;
                var strings = l.ToList();
                var allStringsNullOrEmpty = strings.All(s => s.IsNullOrEmpty());
                if (!strings.HasAny() || allStringsNullOrEmpty)
                {
                    return(CreateConditionlessFilterDescriptor(dictionary, type));
                }
            }
            else if (value is IEnumerable <object> )
            {
                var l = (IEnumerable <object>)value;
                if (!l.HasAny())
                {
                    return(CreateConditionlessFilterDescriptor(dictionary, type));
                }
            }
            else if (value is FilterBase)
            {
                var bf = (FilterBase)value;
                if (bf.IsConditionless)
                {
                    return(CreateConditionlessFilterDescriptor(bf, type));
                }
            }
            else if (value is FilterDescriptor <T> )
            {
                var bf = (FilterDescriptor <T>)value;
                if (bf.IsConditionless)
                {
                    return(CreateConditionlessFilterDescriptor(bf, type));
                }
            }
            else if (value is BaseQuery)
            {
                var bf = (BaseQuery)value;
                if (bf.IsConditionless)
                {
                    return(CreateConditionlessFilterDescriptor(bf, type));
                }
            }

            if (key.IsConditionless())
            {
                return(CreateConditionlessFilterDescriptor(value, type));
            }

            return(bucket);
        }