Class FuzzyScorer
java.lang.Object
org.aesh.readline.fuzzy.FuzzyScorer
High-level API for fuzzy filtering and ranking of text entries.
Use this class to filter a list of history entries (or any text entries) against a fuzzy pattern. Results are sorted by score (descending), with ties broken by recency (most recent first).
The scorer supports:
- Case-insensitive matching (default)
- Deduplication of identical entries (most recent kept)
- Lazy narrowing: when a character is appended to the query, only the previous result set is re-filtered instead of the full list
Not thread-safe — use one instance per search session.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA scored entry: an input text with its fuzzy match result and original index. -
Constructor Summary
ConstructorsConstructorDescriptionFuzzyScorer(FuzzyScheme scheme) Create a case-insensitive scorer with the given scheme.FuzzyScorer(FuzzyScheme scheme, boolean caseSensitive) Create a scorer with the given scheme and case sensitivity. -
Method Summary
Modifier and TypeMethodDescriptionstatic List<int[]> deduplicate(List<int[]> entries) Deduplicate entries, keeping only the most recent occurrence.narrow(List<FuzzyScorer.ScoredEntry> previousResults, int[] pattern, boolean withPos) Narrow a previous result set by scoring against a longer pattern.score(int[] text, int[] pattern, boolean withPos) Score a single text entry against a pattern.Filter and rank a list of entries against a pattern.Filter and rank a list of entries against a pattern, with timestamps.
-
Constructor Details
-
FuzzyScorer
Create a scorer with the given scheme and case sensitivity.- Parameters:
scheme- the scoring schemecaseSensitive- whether matching is case-sensitive
-
FuzzyScorer
Create a case-insensitive scorer with the given scheme.- Parameters:
scheme- the scoring scheme
-
-
Method Details
-
score
Score a single text entry against a pattern.- Parameters:
text- the text as code pointspattern- the search pattern as code pointswithPos- whether to compute match positions- Returns:
- the match result
-
scoreAll
Filter and rank a list of entries against a pattern.Entries are deduplicated (most recent occurrence kept), scored against the pattern, filtered to matches only, and sorted by score descending (ties broken by recency).
- Parameters:
entries- the entries to search (most recent last, as from History.getAll())pattern- the search pattern as code pointswithPos- whether to compute match positions for each entry- Returns:
- sorted list of scored entries (best match first)
-
scoreAll
public List<FuzzyScorer.ScoredEntry> scoreAll(List<int[]> entries, List<Long> timestamps, int[] pattern, boolean withPos) Filter and rank a list of entries against a pattern, with timestamps.- Parameters:
entries- the entries to search (most recent last, as from History.getAll())timestamps- parallel list of timestamps (epoch millis), or nullpattern- the search pattern as code pointswithPos- whether to compute match positions for each entry- Returns:
- sorted list of scored entries (best match first)
-
narrow
public List<FuzzyScorer.ScoredEntry> narrow(List<FuzzyScorer.ScoredEntry> previousResults, int[] pattern, boolean withPos) Narrow a previous result set by scoring against a longer pattern.This is an optimization for interactive typing: when the user appends a character to the query, we only need to re-score the entries that already matched the shorter pattern.
- Parameters:
previousResults- the results from the previous (shorter) patternpattern- the new (longer) pattern as code pointswithPos- whether to compute match positions- Returns:
- narrowed and re-sorted results
-
deduplicate
Deduplicate entries, keeping only the most recent occurrence. Input order: oldest first (index 0) to most recent (last index). Output order: most recent first (for display).- Parameters:
entries- the entries to deduplicate (oldest first)- Returns:
- deduplicated list with most recent entries first
-