예제 #1
0
        public virtual ICharSequence Escape(ICharSequence text, CultureInfo locale, EscapeQuerySyntaxType type)
        {
            if (text == null || text.Length == 0)
            {
                return(text);
            }

            // escape wildcards and the escape char (this has to be perform before
            // anything else)
            // since we need to preserve the UnescapedCharSequence and escape the
            // original escape chars
            if (text is UnescapedCharSequence)
            {
                text = ((UnescapedCharSequence)text).ToStringEscaped(wildcardChars);
            }
            else
            {
                text = new UnescapedCharSequence(text).ToStringEscaped(wildcardChars);
            }

            if (type == EscapeQuerySyntaxType.STRING)
            {
                return(EscapeQuoted(text, locale));
            }
            else
            {
                return(EscapeTerm(text, locale));
            }
        }
        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);
        }
예제 #3
0
        protected override IQueryNode PostProcessNode(IQueryNode node)
        {
            if (node is WildcardQueryNode wildcardNode)
            {
                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 '?':
                        // LUCENENET: Factored out NLS/Message/IMessage so end users can optionally utilize the built-in .NET localization.
                        throw new QueryNodeException(string.Format(
                                                         QueryParserMessages.LEADING_WILDCARD_NOT_ALLOWED, node
                                                         .ToQueryString(new EscapeQuerySyntax())));
                    }
                }
            }

            return(node);
        }
예제 #4
0
        private bool IsPrefixWildcard(string text)
        {
            if (text is null || text.Length <= 0 || !IsWildcard(text))
            {
                return(false);
            }

            // Validate last character is a '*' and was not escaped
            // If single '*' is is a wildcard not prefix to simulate old queryparser
            if (text[text.Length - 1] != '*')
            {
                return(false);
            }
            if (UnescapedCharSequence.WasEscaped(new StringCharSequence(text), text.Length - 1))
            {
                return(false);
            }
            if (text.Length == 1)
            {
                return(false);
            }

            // Only make a prefix if there is only one single star at the end and no '?' or '*' characters
            // If single wildcard return false to mimic old queryparser
            for (int i = 0; i < text.Length; i++)
            {
                if (text[i] == '?')
                {
                    return(false);
                }
                if (text[i] == '*' && !UnescapedCharSequence.WasEscaped(new StringCharSequence(text), i))
                {
                    if (i == text.Length - 1)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            return(false);
        }
예제 #5
0
        private static bool IsWildcard(string text) // LUCENENET: CA1822: Mark members as static
        {
            if (text is null || text.Length <= 0)
            {
                return(false);
            }

            // If a un-escaped '*' or '?' if found return true
            // start at the end since it's more common to put wildcards at the end
            for (int i = text.Length - 1; i >= 0; i--)
            {
                if ((text[i] == '*' || text[i] == '?') && !UnescapedCharSequence.WasEscaped(new StringCharSequence(text), i))
                {
                    return(true);
                }
            }

            return(false);
        }
        private bool IsWildcard(string text)
        {
            if (text == null || text.Length <= 0)
            {
                return(false);
            }

            // If a un-escaped '*' or '?' if found return true
            // start at the end since it's more common to put wildcards at the end
            for (int i = text.Length - 1; i >= 0; i--)
            {
                if ((text[i] == '*' || text[i] == '?') && !UnescapedCharSequence.WasEscaped(new StringCharSequenceWrapper(text), i))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #7
0
        protected override IQueryNode PostProcessNode(IQueryNode node)
        {
            CultureInfo locale = GetQueryConfigHandler().Get(ConfigurationKeys.LOCALE);

            if (locale == null)
            {
                locale = CultureInfo.InvariantCulture; //Locale.getDefault();
            }

            if (node is WildcardQueryNode ||
                node is FuzzyQueryNode ||
                (node is FieldQueryNode && node.Parent is IRangeQueryNode) ||
                node is RegexpQueryNode)
            {
                ITextableQueryNode txtNode = (ITextableQueryNode)node;
                ICharSequence      text    = txtNode.Text;
                txtNode.Text = text != null?UnescapedCharSequence.ToLowerCase(text, locale) : null;
            }

            return(node);
        }