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); }
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); }
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); }
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); }