Fixes to mod_f and mod_d commands working not as expected

This commit is contained in:
REDNBLACK 2017-01-05 23:40:53 +03:00
parent 5ae8e5e3df
commit 83c9975fbb
1 changed files with 6 additions and 4 deletions

View File

@ -76,7 +76,10 @@ class TrigramRepository(RedisRepository):
for pair in redis.scan_iter(match=search_pattern, count=max_results):
(first, second) = pair.decode(encoding).lstrip(format_pattern).split(self.separator)
words.add(first if similar_word in first else second)
if first.startswith(similar_word):
words.add(first)
if second.startswith(similar_word):
words.add(second)
return list(words)[:10]
@ -86,9 +89,8 @@ class TrigramRepository(RedisRepository):
:param chat_id: ID of chat
:param exact_word: Exact word match
"""
self.__remove_keys(self.source_name.format(chat_id, exact_word + self.separator + '*'))
self.__remove_keys(self.source_name.format(chat_id, '*' + self.separator + exact_word))
self.__remove_keys(self.source_name.format(chat_id, exact_word + "\\" + self.separator + '*'))
self.__remove_keys(self.source_name.format(chat_id, '*' + "\\" + self.separator + exact_word))
# FIXME. Not optimal performance wise
def __remove_keys(self, pattern):