public final class SearchInputParsingUtils extends Object
Modifier and Type | Method and Description |
---|---|
static String |
compressWhitespace(String text)
Compress whitespace (tab, newline, multiple spaces) by removing leading and trailing whitespace, and reducing
in-between whitespace to one space.
|
static boolean |
isSpecialChar(char c) |
static String |
parse(String input,
boolean allowSingleNonLeadingWildCardPerTerm)
Returns a parsed version of the input.
|
static String |
parse(String input,
boolean allowSingleNonLeadingWildCardPerTerm,
boolean retainWordBoundaries)
Returns a parsed version of the input.
|
static String |
parse(String input,
boolean allowSingleNonLeadingWildCardPerTerm,
char[] ignore)
Returns a parsed version of the input.
|
static String |
parse(String input,
boolean allowSingleNonLeadingWildCardPerTerm,
char[] ignore,
boolean retainWordBoundaries)
Returns a parsed version of the input.
|
static String |
parse(String input,
boolean allowSingleNonLeadingWildCardPerTerm,
int maxLength)
Returns a parsed version of the input.
|
static String |
parse(String input,
boolean allowSingleNonLeadingWildCardPerTerm,
int maxLength,
char[] ignore)
Returns a parsed version of the input.
|
static String |
parse(String input,
boolean allowSingleNonLeadingWildCardPerTerm,
int maxLength,
char[] ignore,
boolean retainWordBoundaries)
Returns a parsed version of the input.
|
static String |
removeInvalidAndEscapeChars(String input,
boolean allowSingleNonLeadingWildCardPerTerm)
Removes invalid chars, escapes some chars.
|
static String |
removeInvalidAndEscapeChars(String input,
boolean allowSingleNonLeadingWildCardPerTerm,
char[] ignore)
Removes invalid chars, escapes some chars.
|
static String |
removeInvalidAndEscapeChars(String input,
boolean allowSingleNonLeadingWildCardPerTerm,
char[] ignore,
boolean retainWordBoundaries)
Removes invalid chars, escapes some chars.
|
static String |
removeLeadingOrTrailingOrOperator(String input)
Removes the logical operator "OR" at the end of the query.
|
static String |
removeLeadingWildCardsFromWords(String input) |
public static String parse(String input, boolean allowSingleNonLeadingWildCardPerTerm)
input
- the user inputallowSingleNonLeadingWildCardPerTerm
- if there is allowed one wildcard (* or ?) per term (however, still
not allowed as leading for a term)input
. When input
is null
,
null
is returned
Calls #parse(input, allowSingleNonLeadingWildCardPerTerm, null, true)
public static String parse(String input, boolean allowSingleNonLeadingWildCardPerTerm, boolean retainWordBoundaries)
#parse(input, allowSingleNonLeadingWildCardPerTerm, null, retainWordBoundaries)
input
- the user inputallowSingleNonLeadingWildCardPerTerm
- if there is allowed one wildcard (* or ?) per term (however, still
not allowed as leading for a term)retainWordBoundaries
- whether to retain characters such as ~ & ! when they appear in a
token as word boundaries or remove them, see also
isSpecialChar(char)
input
. When input
is null
,
null
is returnedpublic static String parse(String input, boolean allowSingleNonLeadingWildCardPerTerm, char[] ignore)
#parse(input, allowSingleNonLeadingWildCardPerTerm, ignore, true)
input
- the user inputallowSingleNonLeadingWildCardPerTerm
- if there is allowed one wildcard (* or ?) per term (however, still
not allowed as leading for a term)ignore
- the chars that should not be parsedinput
. When input
is null
,
null
is returnedpublic static String parse(String input, boolean allowSingleNonLeadingWildCardPerTerm, char[] ignore, boolean retainWordBoundaries)
input
- the user inputallowSingleNonLeadingWildCardPerTerm
- if there is allowed one wildcard (* or ?) per term (however, still
not allowed as leading for a term)ignore
- the chars that should not be parsedretainWordBoundaries
- whether to retain characters such as ~ & ! when they appear in a
token as word boundaries or remove them, see also
isSpecialChar(char)
input
. When input
is null
,
null
is returnedpublic static String parse(String input, boolean allowSingleNonLeadingWildCardPerTerm, int maxLength)
#parse(input, allowSingleNonLeadingWildCardPerTerm, maxLength, null, true)
input
- the user inputallowSingleNonLeadingWildCardPerTerm
- if there is allowed one wildcard (* or ?) per term (however, still
not allowed as leading for a term)maxLength
- the maxLength of the returned parsed inputinput
. When input
is null
,
null
is returnedpublic static String parse(String input, boolean allowSingleNonLeadingWildCardPerTerm, int maxLength, char[] ignore)
#parse(input, allowSingleNonLeadingWildCardPerTerm, maxLength, ignore, true)
input
- the user inputallowSingleNonLeadingWildCardPerTerm
- if there is allowed one wildcard (* or ?) per term (however, still
not allowed as leading for a term)maxLength
- the maxLength of the returned parsed inputignore
- the chars that should not be parsedinput
. When input
is null
,
null
is returnedpublic static String parse(String input, boolean allowSingleNonLeadingWildCardPerTerm, int maxLength, char[] ignore, boolean retainWordBoundaries)
input
- the user inputallowSingleNonLeadingWildCardPerTerm
- if there is allowed one wildcard (* or ?) per term (however, still
not allowed as leading for a term)maxLength
- the maxLength of the returned parsed inputignore
- the chars that should not be parsedretainWordBoundaries
- whether to retain characters such as ~ & ! when they appear in a
token as word boundaries or remove them, see also
isSpecialChar(char)
input
. When input
is null
,
null
is returnedpublic static String removeInvalidAndEscapeChars(String input, boolean allowSingleNonLeadingWildCardPerTerm)
Removes invalid chars, escapes some chars. If allowSingleNonLeadingWildCard
is true
,
there is one single non leading *
or ?
allowed. Note, that this wildcard is not allowed
to be leading of a new word.
Recommended is to remove all wildcards
input
- the user inputallowSingleNonLeadingWildCardPerTerm
- if there is allowed one wildcard (* or ?) per term (however, still
not allowed as leading for a term)input
public static String removeInvalidAndEscapeChars(String input, boolean allowSingleNonLeadingWildCardPerTerm, char[] ignore)
Removes invalid chars, escapes some chars. If allowSingleNonLeadingWildCard
is true
,
there is one single non leading *
or ?
allowed. Note, that this wildcard is not allowed
to be leading of a new word.
Recommended is to remove all wildcards
input
- the user inputallowSingleNonLeadingWildCardPerTerm
- if there is allowed one wildcard (* or ?) per term (however, still
not allowed as leading for a term)ignore
- the chars that should not be parsedinput
public static String removeInvalidAndEscapeChars(String input, boolean allowSingleNonLeadingWildCardPerTerm, char[] ignore, boolean retainWordBoundaries)
Removes invalid chars, escapes some chars. If allowSingleNonLeadingWildCard
is true
,
there is one single non leading *
or ?
allowed. Note, that this wildcard is not allowed
to be leading of a new word.
Recommended is to remove all wildcards
input
- the user inputallowSingleNonLeadingWildCardPerTerm
- if there is allowed one wildcard (* or ?) per term (however, still
not allowed as leading for a term)ignore
- the chars that should not be parsedretainWordBoundaries
- whether to retain special characters as word boundaries or remove
theminput
public static boolean isSpecialChar(char c)
public static String removeLeadingOrTrailingOrOperator(String input)
input
- the original (possibly invalid) query stringpublic static String compressWhitespace(String text)
text
- the text to compress (may be null)Copyright © 2008–2016 Hippo B.V. (http://www.onehippo.com). All rights reserved.