Skip to content

textual.fuzzy

Fuzzy matcher.

This class is used by the command palette to match search terms.

FuzzySearch

FuzzySearch(case_sensitive=False, *, cache_size=1024 * 4)

Performs a fuzzy search.

Unlike a regex solution, this will finds all possible matches.

Parameters:

Name Type Description Default
case_sensitive bool

Is the match case sensitive?

False
cache_size int

Number of queries to cache.

1024 * 4

match

match(query, candidate)

Match against a query.

Parameters:

Name Type Description Default
query str

The fuzzy query.

required
candidate str

A candidate to check,.

required

Returns:

Type Description
tuple[float, Sequence[int]]

A pair of (score, tuple of offsets). (0, ()) for no result.

score

score(candidate, positions)

Score a search.

Parameters:

Name Type Description Default
search

Search object.

required

Returns:

Type Description
float

Score.

Matcher

Matcher(query, *, match_style=None, case_sensitive=False)

A fuzzy matcher.

Parameters:

Name Type Description Default
query str

A query as typed in by the user.

required
match_style Style | None

The style to use to highlight matched portions of a string.

None
case_sensitive bool

Should matching be case sensitive?

False

case_sensitive property

case_sensitive: bool

Is this matcher case sensitive?

match_style property

match_style: Style

The style that will be used to highlight hits in the matched text.

query property

query: str

The query string to look for.

highlight

highlight(candidate)

Highlight the candidate with the fuzzy match.

Parameters:

Name Type Description Default
candidate str

The candidate string to match against the query.

required

Returns:

Type Description
Content

A Text object with highlighted matches.

match

match(candidate)

Match the candidate against the query.

Parameters:

Name Type Description Default
candidate str

Candidate string to match against the query.

required

Returns:

Type Description
float

Strength of the match from 0 to 1.