From a623210244df5c10fae8bc8106b4be822a4bd44c Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Fri, 8 Sep 2023 16:19:39 -0600 Subject: [PATCH] Match exact words to trigger calculator widget The calculator was previously triggered for partial matches with words like "calc", which meant searches containing the word "calcium" would cause the calculator widget to appear. --- app/utils/search.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/utils/search.py b/app/utils/search.py index f643cbe..6e2d62d 100644 --- a/app/utils/search.py +++ b/app/utils/search.py @@ -109,7 +109,9 @@ class Search: self.widget = "ip" if re.search("([^a-z0-9]|^)my *[^a-z0-9] *(ip|internet protocol)" + "($|( *[^a-z0-9] *(((addres|address|adres|" + "adress)|a)? *$)))", self.query.lower()) else self.widget - self.widget = 'calculator' if re.search("calculator|calc|calclator|math", self.query.lower()) else self.widget + self.widget = 'calculator' if re.search( + r"\bcalculator\b|\bcalc\b|\bcalclator\b|\bmath\b", + self.query.lower()) else self.widget return self.query def generate_response(self) -> str: