Exemplo n.º 1
0
        protected override IQueryNode PostProcessNode(IQueryNode node)
        {
            // the old Lucene Parser ignores FuzzyQueryNode that are also PrefixWildcardQueryNode or WildcardQueryNode
            // we do the same here, also ignore empty terms
            if (node is FieldQueryNode || node is FuzzyQueryNode)
            {
                FieldQueryNode fqn  = (FieldQueryNode)node;
                string         text = fqn.Text.ToString();

                // do not process wildcards for TermRangeQueryNode children and
                // QuotedFieldQueryNode to reproduce the old parser behavior
                if (fqn.Parent is TermRangeQueryNode ||
                    fqn is QuotedFieldQueryNode ||
                    text.Length <= 0)
                {
                    // Ignore empty terms
                    return(node);
                }

                // Code below simulates the old lucene parser behavior for wildcards

                if (IsPrefixWildcard(text))
                {
                    PrefixWildcardQueryNode prefixWildcardQN = new PrefixWildcardQueryNode(fqn);
                    return(prefixWildcardQN);
                }
                else if (IsWildcard(text))
                {
                    WildcardQueryNode wildcardQN = new WildcardQueryNode(fqn);
                    return(wildcardQN);
                }
            }

            return(node);
        }
        protected override IQueryNode PostProcessNode(IQueryNode node)
        {
            if (node is WildcardQueryNode)
            {
                WildcardQueryNode wildcardNode = (WildcardQueryNode)node;

                if (wildcardNode.Text.Length > 0)
                {
                    // Validate if the wildcard was escaped
                    if (UnescapedCharSequence.WasEscaped(wildcardNode.Text, 0))
                    {
                        return(node);
                    }

                    switch (wildcardNode.Text[0])
                    {
                    case '*':
                    case '?':
                        throw new QueryNodeException(new Message(
                                                         QueryParserMessages.LEADING_WILDCARD_NOT_ALLOWED, node
                                                         .ToQueryString(new EscapeQuerySyntax())));
                    }
                }
            }

            return(node);
        }
        public virtual Query Build(IQueryNode queryNode)
        {
            WildcardQueryNode wildcardNode = (WildcardQueryNode)queryNode;

            WildcardQuery q = new WildcardQuery(new Term(wildcardNode.GetFieldAsString(),
                                                         wildcardNode.GetTextAsString()));

            MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod)queryNode.GetTag(MultiTermRewriteMethodProcessor.TAG_ID);
            if (method != null)
            {
                q.MultiTermRewriteMethod = method;
            }

            return(q);
        }