Skip to content

Fuzzy matcher

Fuzzy matcher.

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

Matcher class

def __init__(
    self, 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.

query_pattern property

query_pattern: str

The regular expression pattern built from the query.

highlight method

def highlight(self, 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 method

def match(self, 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.