Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def search_by_true_name(self, name, threshold=80):
"""Finds all items which match closely to all given query parameters.
Args:
name: Name to search by. Ignored if None.
threshold: Threshold for matching with RapidFuzz.
Returns:
List of matching triplets with NameItem, RapidFuzz ratio and RapidFuzz token_set_ratio
"""
matches = []
for item in self.items:
# Search with false name
ratio = fuzz.ratio(item.true_name, name)
token_set_ratio = fuzz.token_set_ratio(item.true_name.lower(), name.lower())
if ratio > threshold or token_set_ratio > threshold:
matches.append((item, ratio, token_set_ratio))
return sorted(matches, key=lambda x: x[1], reverse=True)
def search_by_false_name(self, name, threshold=80):
"""Finds all items which match closely to all given query parameters.
Args:
name: Name to search by. Ignored if None.
threshold: Threshold for matching with RapidFuzz.
Returns:
List of matching triplets with NameItem, RapidFuzz ratio and RapidFuzz token_set_ratio
"""
matches = []
for item in self.items:
# Search with false name
ratio = fuzz.ratio(item.false_name, name)
token_set_ratio = fuzz.token_set_ratio(item.false_name.lower(), name.lower())
if ratio > threshold or token_set_ratio > threshold:
matches.append((item, ratio, token_set_ratio))
return sorted(matches, key=lambda x: x[1], reverse=True)