Package de.cxp.ocs.smartsuggest.util
Class Util
java.lang.Object
de.cxp.ocs.smartsuggest.util.Util
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic double
commonChars
(@NonNull Locale locale, @NonNull String input, @NonNull String target) Returns the common chars of an input string compared to an target string.static Comparator
<Suggestion> getCommonCharsComparator
(Locale locale, String term) Returns theComparator
that orders suggestion with according to their common chars to the given 'term'.static Comparator
<Suggestion> getCommonPrefixComparator
(Locale locale, String term) Returns theComparator
that orders suggestion according to their common prefix to the given 'term'.static int
static Comparator
<Suggestion> getDefaultComparator
(Locale locale, String inputTerm) Retrieve comparator to order suggestions within a group: First prefer the ones with higher weight Then prefer the ones with more common chars with the input term Finally do natural sorting to get consistent orderingstatic Comparator
<Suggestion> Returns theComparator
used to sort suggestions by their weight, where queries of the group "sharpened matches" are preferred over all others (=max weight).static Comparator
<Suggestion> getFuzzySuggestionsComparator
(Locale locale, String inputTerm) Retrieve comparator to optimally order fuzzy suggestions: First prefer the ones with more common prefix with the input term Then prefer the ones with more common chars with the input term Then prefer the ones with higher weight Finally do natural sorting to get consistent orderingstatic Collector
<org.apache.lucene.search.suggest.Lookup.LookupResult, ?, List<org.apache.lucene.search.suggest.Lookup.LookupResult>> getTopKFuzzySuggestionCollector
(int topK, Locale locale, String inputTerm) Collector to get the first N suggestions by this order: First prefer the ones with more common prefix with the input term Then prefer the ones with more common chars with the input term Finally prefer the ones with higher weight
-
Field Details
-
APP_NAME
- See Also:
-
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
commonChars
public static double commonChars(@NonNull @NonNull Locale locale, @NonNull @NonNull String input, @NonNull @NonNull String target) Returns the common chars of an input string compared to an target string. The logic works directional, so it's important to always compare to the same target and change the input- Parameters:
locale
- the locale used to any string normalizationsinput
- the input string to compare against the targettarget
- the target string- Returns:
- a value between
1
and0
, where1
means all chars are common and0
means no chars are common.
-
getCommonPrefixComparator
Returns the
Comparator
that orders suggestion according to their common prefix to the given 'term'. Queries with a longer common prefix are preferred.- Parameters:
locale
- the locale of the client. Used to load the proper stopwordsterm
- the term for which to get suggestions- Returns:
- the
Comparator
-
getCommonPrefixLength
-
getCommonCharsComparator
Returns the
Comparator
that orders suggestion with according to their common chars to the given 'term'. Queries with more common chars are preferred.- Parameters:
locale
- the locale of the client. Used to load the proper stopwordsterm
- the term for which to get suggestions- Returns:
- the
Comparator
-
getDescendingWeightComparator
Returns theComparator
used to sort suggestions by their weight, where queries of the group "sharpened matches" are preferred over all others (=max weight).- Returns:
- the
Comparator
for sharpened suggestions.
-
getTopKFuzzySuggestionCollector
public static Collector<org.apache.lucene.search.suggest.Lookup.LookupResult,?, getTopKFuzzySuggestionCollectorList<org.apache.lucene.search.suggest.Lookup.LookupResult>> (int topK, Locale locale, String inputTerm) Collector to get the first N suggestions by this order:- First prefer the ones with more common prefix with the input term
- Then prefer the ones with more common chars with the input term
- Finally prefer the ones with higher weight
- Parameters:
topK
- amount of suggestions to collectlocale
- localeinputTerm
- term of the user- Returns:
- a suggestion collector
-
getFuzzySuggestionsComparator
Retrieve comparator to optimally order fuzzy suggestions:- First prefer the ones with more common prefix with the input term
- Then prefer the ones with more common chars with the input term
- Then prefer the ones with higher weight
- Finally do natural sorting to get consistent ordering
- Parameters:
locale
-inputTerm
-- Returns:
-
getDefaultComparator
Retrieve comparator to order suggestions within a group:- First prefer the ones with higher weight
- Then prefer the ones with more common chars with the input term
- Finally do natural sorting to get consistent ordering
- Parameters:
locale
-inputTerm
-- Returns:
-