From 547b6c37e1cfc7d90bb98a77aa57e66332bd95c9 Mon Sep 17 00:00:00 2001 From: Sep Dehpour Date: Tue, 15 Jan 2019 23:11:20 -0800 Subject: [PATCH] dealing with spaces --- fast_autocomplete/__init__.py | 2 +- fast_autocomplete/dwg.py | 8 ++++++-- tests/test_autocomplete.py | 7 +++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/fast_autocomplete/__init__.py b/fast_autocomplete/__init__.py index b23fd80..b3d5bae 100644 --- a/fast_autocomplete/__init__.py +++ b/fast_autocomplete/__init__.py @@ -1,5 +1,5 @@ # flake8: noqa -__version__ = '0.2.2' +__version__ = '0.2.3' import sys pyversion = float(sys.version[:3]) if pyversion < 3.6: diff --git a/fast_autocomplete/dwg.py b/fast_autocomplete/dwg.py index 8dce465..39ed141 100644 --- a/fast_autocomplete/dwg.py +++ b/fast_autocomplete/dwg.py @@ -326,8 +326,12 @@ def _prefix_autofill_part(self, word, node=None, matched_condition_ever=False, m if node.children: if char not in node.children: - que.appendleft(char) - break + space_child = node.children.get(' ') + if space_child and char in space_child.children: + node = space_child + else: + que.appendleft(char) + break node = node.children[char] if char != ' ' or matched_prefix_of_last_word: matched_prefix_of_last_word += char diff --git a/tests/test_autocomplete.py b/tests/test_autocomplete.py index 8514df3..9398826 100644 --- a/tests/test_autocomplete.py +++ b/tests/test_autocomplete.py @@ -282,6 +282,13 @@ def test_search_without_synonyms(self, word, max_cost, size, expected_results): 'expected_steps': STEP_DESCENDANTS_ONLY, 'expected_find_and_sort_results': [['truck']], }, + {'word': '1se', + 'max_cost': 3, + 'size': 5, + 'expected_find_results': {1: [['1 series']]}, + 'expected_steps': STEP_DESCENDANTS_ONLY, + 'expected_find_and_sort_results': [['1 series']], + }, ]