public abstract class SearchMatcher
extends java.lang.Object
This class is abstract. You can obtain an instance of a specific matching algorithm by calling one of the static factory methods.
Two standard implementations are provided.
substring matcher
will return true if the text to search contains the search string as a
substring.
prefix matcher
will return true if any of the words in the text to search are prefixed by
any of the words in the search string. A word is any sequence of letters or
digits surrounded by non digits or letters (e.g. whitespace, symbols)
The recommended default for general text search is the prefix matcher configured to be case insensitive and exclusive, i.e.:
SearchMatcher m = SearchMatcher.getPrefixMatcher( "search text", true, true );Only use the substring matcher if performance is a significant issue (although, since you should usually be searching short, local Strings, this should rarely be the case).
Constructor and Description |
---|
SearchMatcher() |
Modifier and Type | Method and Description |
---|---|
static SearchMatcher |
getPrefixMatcher(java.lang.CharSequence searchString,
boolean ignoreCase,
boolean exclusive)
Returns a matcher which will match if any of the words in the search
string can be found as prefixes of words in the text to search.
|
static SearchMatcher |
getSubstringMatcher(java.lang.CharSequence searchString,
boolean ignoreCase)
Returns a matcher which will match if the text to search contains the
complete search string at any position.
|
abstract boolean |
matches(java.lang.CharSequence textToSearch)
Returns true if the specified searchString was
successfully matched with the textToSearch.
|
java.lang.CharSequence |
searchString()
Returns the search string this matcher will match.
|
public abstract boolean matches(java.lang.CharSequence textToSearch)
textToSearch
- the text to search. Must not be null.public java.lang.CharSequence searchString()
public static SearchMatcher getSubstringMatcher(java.lang.CharSequence searchString, boolean ignoreCase)
searchString
- the search string.ignoreCase
- if true, case will be considered insignificant
while matching.public static SearchMatcher getPrefixMatcher(java.lang.CharSequence searchString, boolean ignoreCase, boolean exclusive)
The exclusive parameter can be used to control whether this is a mutually exclusive (OR) search (the match will be successful if any of the words in the search string are prefixes of words in the text to search), or an AND search (the match will be successful if all of the words in the search string are prefixes of words in the text to search).
searchString
- the search string.ignoreCase
- if true, case will be considered insignificant
while matching.exclusive
- if true, the match will be successful if
any of the words in the search string are prefixes of words in
the text to search. If false, the match will be successful if
all of the words in the search string are prefixes of words in
the text to search.