Exemplo n.º 1
0
        private Expression BindAnyQueryNode(AnyQueryNode anyQueryNode)
        {
            ParameterExpression anyIt = HandleLambdaParameters(anyQueryNode.Parameters);

            Expression source;

            Contract.Assert(anyQueryNode.Source != null);
            source = Bind(anyQueryNode.Source);

            Expression body = null;

            // uri parser places an Constant node with value true for empty any() body
            if (anyQueryNode.Body != null && anyQueryNode.Body.Kind != QueryNodeKind.Constant)
            {
                body = Bind(anyQueryNode.Body);
                body = ApplyNullPropagationForFilterBody(body);
                body = Expression.Lambda(body, anyIt);
            }

            Expression any = Any(source, body);

            if (_querySettings.HandleNullPropagation == HandleNullPropagationOption.True && IsNullable(source.Type))
            {
                // IFF(source == null) null; else Any(body);
                any = ToNullable(any);
                return(Expression.Condition(
                           test: Expression.Equal(source, _nullConstant),
                           ifTrue: Expression.Constant(null, any.Type),
                           ifFalse: any));
            }
            else
            {
                return(any);
            }
        }
Exemplo n.º 2
0
        public virtual Query Build(IQueryNode queryNode)
        {
            AnyQueryNode andNode = (AnyQueryNode)queryNode;

            BooleanQuery       bQuery   = new BooleanQuery();
            IList <IQueryNode> children = andNode.GetChildren();

            if (children != null)
            {
                foreach (IQueryNode child in children)
                {
                    object obj = child.GetTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);

                    if (obj != null)
                    {
                        Query query = (Query)obj;

                        try
                        {
                            bQuery.Add(query, Occur.SHOULD);
                        }
                        catch (BooleanQuery.TooManyClausesException ex)
                        {
                            // LUCENENET: Factored out NLS/Message/IMessage so end users can optionally utilize the built-in .NET localization.
                            throw new QueryNodeException(

                                      /*
                                       * IQQQ.Q0028E_TOO_MANY_BOOLEAN_CLAUSES,
                                       * BooleanQuery.getMaxClauseCount()
                                       */
                                      QueryParserMessages.EMPTY_MESSAGE, ex);
                        }
                    }
                }
            }

            bQuery.MinimumNumberShouldMatch = andNode.MinimumMatchingElements;

            return(bQuery);
        }
Exemplo n.º 3
0
        public virtual Query Build(IQueryNode queryNode)
        {
            AnyQueryNode andNode = (AnyQueryNode)queryNode;

            BooleanQuery       bQuery   = new BooleanQuery();
            IList <IQueryNode> children = andNode.GetChildren();

            if (children != null)
            {
                foreach (IQueryNode child in children)
                {
                    object obj = child.GetTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);

                    if (obj != null)
                    {
                        Query query = (Query)obj;

                        try
                        {
                            bQuery.Add(query, BooleanClause.Occur.SHOULD);
                        }
                        catch (BooleanQuery.TooManyClauses ex)
                        {
                            throw new QueryNodeException(new MessageImpl(

                                                             /*
                                                              * IQQQ.Q0028E_TOO_MANY_BOOLEAN_CLAUSES,
                                                              * BooleanQuery.getMaxClauseCount()
                                                              */QueryParserMessages.EMPTY_MESSAGE), ex);
                        }
                    }
                }
            }

            bQuery.MinimumNumberShouldMatch = andNode.MinimumMatchingElements;

            return(bQuery);
        }