diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 4121df8e1a2..28b41bad262 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -1626,7 +1626,7 @@ class Website(models.Model): :param limit: maximum number of records fetched per model to build the word list :return: yields words """ - match_pattern = '\\w{%s,}' % min(4, len(search) - 3) + match_pattern = r'[\w-]{%s,}' % min(4, len(search) - 3) similarity_threshold = 0.3 for search_detail in search_details: model_name, fields = search_detail['model'], search_detail['search_fields'] @@ -1742,7 +1742,7 @@ class Website(models.Model): :param limit: maximum number of records fetched per model to build the word list :return: yields words """ - match_pattern = '\\w{%s,}' % min(4, len(search) - 3) + match_pattern = r'[\w-]{%s,}' % min(4, len(search) - 3) first = escape_psql(search[0]) for search_detail in search_details: model_name, fields = search_detail['model'], search_detail['search_fields'] diff --git a/addons/website/tests/test_fuzzy.py b/addons/website/tests/test_fuzzy.py index 8655e25ae2a..2f4f89014b1 100644 --- a/addons/website/tests/test_fuzzy.py +++ b/addons/website/tests/test_fuzzy.py @@ -125,7 +125,7 @@ class TestAutoComplete(TransactionCase): "Many results contain this page", "How many times does the word many appear", "Will there be many results", - "Welcome to our many friends", + "Welcome to our many friends next week-end", "This should only be approximately matched", ] for text in texts: @@ -245,3 +245,12 @@ class TestAutoComplete(TransactionCase): suggestions = self._autocomplete("iphone7") self.assertEqual(1, suggestions['results_count'], "Test data contains one fuzzy match") self.assertTrue(suggestions['fuzzy_search'], "Expects an fuzzy match") + + def test_09_hyphen(self): + """ Ensures that hyphen is considered part of word """ + suggestions = self._autocomplete("weekend") + self.assertEqual(1, suggestions['results_count'], "Text data contains one page with 'weekend'") + self.assertEqual('week-end', suggestions['fuzzy_search'], "Expects a fuzzy match") + suggestions = self._autocomplete("week-end") + self.assertEqual(1, len(suggestions['results']), "All results must be present") + self.assertFalse(suggestions['fuzzy_search'], "Expects an exact match")