From e5fdb33e31b1c788c759a74b07cf16dfd8fe26af Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 1 Oct 2023 17:46:46 -0400 Subject: [PATCH] Port cache-`dict` search to new `rapidfuzz` api --- piker/ui/_search.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/piker/ui/_search.py b/piker/ui/_search.py index ba81eb1a..d6af5535 100644 --- a/piker/ui/_search.py +++ b/piker/ui/_search.py @@ -43,7 +43,7 @@ from typing import ( Iterator, ) import time -# from pprint import pformat +from pprint import pformat from rapidfuzz import process as fuzzy import trio @@ -1139,21 +1139,25 @@ async def search_simple_dict( ) -> dict[str, Any]: - tokens = [] + tokens: list[str] = [] for key in source: - if not isinstance(key, str): - tokens.extend(key) - else: - tokens.append(key) + match key: + case str(): + tokens.append(key) + case []: + tokens.extend(key) # search routine can be specified as a function such # as in the case of the current app's local symbol cache - matches = fuzzy.extractBests( + matches = fuzzy.extract( text, tokens, score_cutoff=90, ) - + log.info( + 'cache search results:\n' + f'{pformat(matches)}' + ) return [item[0] for item in matches]