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
Parameter Default Description
query
str
required

A query as typed in by the user.

match_style
Style | None
None

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

case_sensitive
bool
False

Should matching be case sensitive?

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
Parameter Default Description
candidate
str
required

The candidate string to match against the query.

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
Parameter Default Description
candidate
str
required

Candidate string to match against the query.

Returns
Type Description
float

Strength of the match from 0 to 1.