Skip to content

Commit

Permalink
fixing #25
Browse files Browse the repository at this point in the history
  • Loading branch information
seperman committed Jun 29, 2021
1 parent 306bd3e commit d6f1d64
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion fast_autocomplete/dwg.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,12 @@ def insert_word_branch(self, word, leaf_node=None, add_word=True, original_key=N
count=count,
insert_count=self.SHOULD_INCLUDE_COUNT
)
temp_leaf_node.children[word[-1]] = leaf_node
# It already has children
if temp_leaf_node.children and word[-1] in temp_leaf_node.children:
temp_leaf_node.children[word[-1]].word = leaf_node.word
# otherwise merge into the leaf node
else:
temp_leaf_node.children[word[-1]] = leaf_node
else:
leaf_node = self._dwg.insert(
word,
Expand Down
7 changes: 7 additions & 0 deletions tests/test_autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ def test_search_unicode_without_synonyms(self, word, max_cost, size, expected_re
print_results(locals())
assert expected_results == results

def test_autocomplete_synonym_part_of_another_word(self):
words = {'cartoon': {}, 'vehicle': {}}
synonyms = {'vehicle': ['car']}
autocomplete = AutoComplete(words=words, synonyms=synonyms)
result = autocomplete.search(word='ca')
assert [['vehicle'], ['cartoon']] == result


STEP_DESCENDANTS_ONLY = [FindStep.descendants_only]
STEP_FUZZY_FOUND = [FindStep.fuzzy_try, FindStep.fuzzy_found]
Expand Down

0 comments on commit d6f1d64

Please sign in to comment.