Skip to content

textual.fuzzy

Fuzzy matcher.

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

FuzzySearch

FuzzySearch(case_sensitive=False)

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

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, tuple[int, ...]]

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

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

Is this matcher case sensitive?

match_style property

match_style

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

query property

query

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
Text

A [rich.text.Text][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.