From 83c9975fbb883f085781a6ac69e302dd6076aae1 Mon Sep 17 00:00:00 2001 From: REDNBLACK Date: Thu, 5 Jan 2017 23:40:53 +0300 Subject: [PATCH] Fixes to mod_f and mod_d commands working not as expected --- src/repository/trigram_repository.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/repository/trigram_repository.py b/src/repository/trigram_repository.py index 0a65e17..6a51d19 100644 --- a/src/repository/trigram_repository.py +++ b/src/repository/trigram_repository.py @@ -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):