TUIFuzzy Matching
DocsTUIFuzzy Matching

Fuzzy Matching

Fuzzy matching utilities for autocomplete

Quick Start

main.py
from connectonion.tui import fuzzy_match, highlight_match # Check if query matches text matched, score, positions = fuzzy_match("gp", "gpt-4") # matched: True # score: 16 (higher = better) # positions: [0, 1] (matched char indices)

fuzzy_match

Match query against text with scoring:

main.py
from connectonion.tui import fuzzy_match matched, score, positions = fuzzy_match(query, text)

Scoring

BonusDescription
+1Per matched character
+10Consecutive character bonus
+5Word boundary bonus (after /_-. )

Examples

main.py
fuzzy_match("gp", "gpt-4") # (True, 16, [0, 1]) fuzzy_match("g4", "gpt-4") # (True, 7, [0, 4]) fuzzy_match("xyz", "gpt-4") # (False, 0, []) fuzzy_match("", "anything") # (True, 0, [])

highlight_match

Highlight matched characters in Rich Text:

main.py
from connectonion.tui import highlight_match from rich.console import Console console = Console() # Get match positions matched, score, positions = fuzzy_match("gp", "gpt-4") # Create highlighted text text = highlight_match("gpt-4", positions) console.print(text) # "gp" highlighted in magenta

API

main.py
fuzzy_match(query: str, text: str) -> tuple[bool, int, list[int]] # Returns: (matched, score, positions) highlight_match(text: str, positions: list[int]) -> Text # Returns: Rich Text with matched chars highlighted

Star us on GitHub

If ConnectOnion saves you time, a ⭐ goes a long way — and earns you a coffee chat with our founder.