Class SearchTextParser
java.lang.Object
ch.tocco.nice2.toolbox.api.string.SearchTextParser
- All Implemented Interfaces:
Iterable<SearchTextParser.QueryTerm>
Parses fulltext search input text as expected.
Rules:
- Any text appearing in quotes is treated as a single search token.
- Duplicates are removed in a case sensitive way.
- Tokens are returned in the order they are found (LinkedHashMap).
- Tokens are trimmed. The only place where (multiple) whitespace remains is within quotes between words, eg "foo bar".
- Wildcard characters in terms are preserved, eg auto*
Limits:
- Does not handle operators AND, OR, NOT.
- Does not handle brackets.
Original source: http://www.javapractices.com/topic/TopicAction.do?Id=87
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
The result of one term in the user's search input. -
Field Summary
Modifier and TypeFieldDescriptionstatic final char
static final char
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
getAmountOfNonWildcard
(String term) Tells how many characters the term contains that are not wildcard chars.iterator()
int
length()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
WILDCARD_ANY
public static final char WILDCARD_ANY- See Also:
-
WILDCARD_SINGLE
public static final char WILDCARD_SINGLE- See Also:
-
-
Constructor Details
-
SearchTextParser
- Parameters:
aSearchText
- May be empty, and represents what the user has input in a search box.
-
-
Method Details
-
getAmountOfNonWildcard
Tells how many characters the term contains that are not wildcard chars. This may be used to decide if the term should better be ignored.- Parameters:
term
- The term.- Returns:
- 0-n
-
length
public int length()- Returns:
- 0-n
-
getTokens
- Returns:
- Unmodifiable set.
-
iterator
- Specified by:
iterator
in interfaceIterable<SearchTextParser.QueryTerm>
-