Fix match imports and simplify fuzzy threshold.

pull/430/head
William Ting 8 years ago
parent 218d779b4d
commit 737563570e

@ -65,7 +65,7 @@ from autojump_utils import sanitize
from autojump_utils import take
from autojump_utils import unico
VERSION = '22.3.2'
VERSION = '22.3.3'
FUZZY_MATCH_THRESHOLD = 0.6
TAB_ENTRIES_COUNT = 9
TAB_SEPARATOR = '__'

@ -2,11 +2,14 @@
# -*- coding: utf-8 -*-
import os
import re
import sys
from difflib import SequenceMatcher
from autojump_utils import is_python3
from autojump_utils import is_windows
from autojump_utils import last
if sys.version_info[0] == 3:
if is_python3():
ifilter = filter
imap = map
os.getcwdu = os.getcwd
@ -73,7 +76,7 @@ def match_consecutive(needles, haystack, ignore_case=False):
regex_no_sep_end = regex_no_sep + '$'
regex_one_sep = regex_no_sep + sep + regex_no_sep
# can't use compiled regex because of flags
regex_needle = regex_one_sep.join(map(re.escape, needles)).replace('\\', '\\\\') + regex_no_sep_end # noqa
regex_needle = regex_one_sep.join(imap(re.escape, needles)).replace('\\', '\\\\') + regex_no_sep_end # noqa
regex_flags = re.IGNORECASE | re.UNICODE if ignore_case else re.UNICODE
found = lambda entry: re.search(
regex_needle,
@ -82,10 +85,10 @@ def match_consecutive(needles, haystack, ignore_case=False):
return ifilter(found, haystack)
def match_fuzzy(needles, haystack, ignore_case=False):
def match_fuzzy(needles, haystack, ignore_case=False, threshold=0.6):
"""
Performs an approximate match with the last needle against the end of
every path past an acceptable threshold (FUZZY_MATCH_THRESHOLD).
every path past an acceptable threshold.
For example:
needles = ['foo', 'bar']
@ -115,6 +118,5 @@ def match_fuzzy(needles, haystack, ignore_case=False):
match_percent = lambda entry: SequenceMatcher(
a=needle,
b=end_dir(entry.path)).ratio()
meets_threshold = lambda entry: match_percent(entry) >= \
FUZZY_MATCH_THRESHOLD
meets_threshold = lambda entry: match_percent(entry) >= threshold
return ifilter(meets_threshold, haystack)

Loading…
Cancel
Save