Esempio n. 1
0
        public DelegateExpressionFilterBuilder(Expression <Func <TSource, Filter> > filterExpression, Func <Filter, Func <string, Filter> > expressionFilterDelegate) : base(null)
        {
            FieldNameMethod = (expression, conventions) => {
                // highjack fieldname method to parse expression since we now know the conventions
                var parser = new FilterExpressionParser(conventions);
                var filter = parser.GetFilter(filterExpression);
                filterDelegate = expressionFilterDelegate(filter);

                return(conventions.FieldNameConvention.GetFieldName(expression));
            };
        }
Esempio n. 2
0
        public static ITypeSearch <TSource> Filter <TSource, TListItem>(this ITypeSearch <TSource> search,
                                                                        Expression <Func <TSource, NestedList <TListItem> > > nestedExpression,
                                                                        Expression <Func <TListItem, Filter> > filterExpression)
        {
            search.ValidateNotNullArgument("search");
            nestedExpression.ValidateNotNullArgument("nestedExpression");
            filterExpression.ValidateNotNullArgument("filterExpression");

            var path = search.Client.Conventions.FieldNameConvention.GetFieldName(nestedExpression);

            if (!path.EndsWith("$$nested"))
            {
                throw new ArgumentException(string.Format("{0} is not a nested object.", nestedExpression.GetReturnType().Name));
            }
            var parser = new FilterExpressionParser(search.Client.Conventions);
            var filter = parser.GetFilter(filterExpression);

            PrependPathOnNestedFilters(path, filter);
            var nestedFilter = new NestedFilter(path, filter);

            return(search.Filter(nestedFilter));
        }
        public static ITypeSearch <TSource> TermsFacetFor <TSource>(
            this ITypeSearch <TSource> search,
            Expression <Func <TSource, string> > fieldSelector, Expression <Func <TSource, Filter> > filterExpression, Action <TermsFacetFilterRequest> facetRequestAction = null)
        {
            filterExpression.ValidateNotNullArgument("filterExpression");
            var filterExpressionParser = new FilterExpressionParser(search.Client.Conventions);
            var facetFilter            = filterExpressionParser.GetFilter(filterExpression);
            var facetName = fieldSelector.GetFieldPath();
            var fieldName = search.Client.Conventions.FieldNameConvention.GetFieldName(fieldSelector);

            return(new Search <TSource, IQuery>(search, context =>
            {
                var facetRequest = new TermsFacetFilterRequest(facetName, facetFilter)
                {
                    Field = fieldName
                };
                if (facetRequestAction.IsNotNull())
                {
                    facetRequestAction(facetRequest);
                }
                context.RequestBody.Facets.Add(facetRequest);
            }));
        }