This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Shell 3.4.0!

Search Algorithms

SearchMatch is an interface to match text with a pattern. Match results are in a returned value SearchMatchResult. Match result contains info about match positions and overall score of a match.

fzf.

Implementations

FuzzyMatchV2Search

Port of fzf FuzzyMatchV2Search algorithm. Does a fast fuzzy search and is good quickly finding paths.

ExactMatchNaive

Port of fzf ExactMatchNaive algorithm. Simple exact match works more accurately if you know what to search.

SearchMatch

Algorithms and default syntax are hidden inside package protected classes as we don’t want to fully open these until we know API’s are good to go for longer support. You need to construct SearchMatch via its build-in builder.

SearchMatch searchMatch = SearchMatch.builder()
	.caseSensitive(false)
	.normalize(false)
	.forward(true)
	.build();

It’s possible to configure case sensitivity, on what direction search happens or if text should be normilized before search happens. Normalization is handy when different languages have sligh variation for same type of characters.

Search algorithm is selected based on a search syntax shown in below table.

Table 1. Search syntax
Token Match type Description

hell

fuzzy-match

Items that match hello

'stuff

exact-match

Items that include stuff

Examples

SearchMatch searchMatch = SearchMatch.builder()
	.caseSensitive(false)
	.normalize(false)
	.forward(true)
	.build();

SearchMatchResult result = searchMatch.match("foo bar baz", "fbb");

result.getStart();
// 0 - start position inclusive
result.getEnd();
// 9 - end position exclusive
result.getPositions();
// 0,4,8 - positions, inclusive
result.getScore();
// 112 - score
result.getAlgorithm();
// FuzzyMatchV2SearchMatchAlgorithm - resolved algo