[FIX] website: fix matching of search term and fuzzy term
Prior to this commit, when a user searches with an upper case search term of more than 3 characters, the search was considered as a fuzzy search even if the result was an exact match. Since the search is always lowered when there are more than 3 characters, the search is considered as fuzzy only when the search and fuzzy term are case insensitively distinct. closes odoo/odoo#84593 X-original-commit: 34362a7c07a2868103b24d16a83a97356ad1f60d Signed-off-by: Romain Derie (rde) <rde@odoo.com>
This commit is contained in:
committed by
Romain Derie
parent
5450f50e35
commit
ecd08f519f
@@ -1521,7 +1521,7 @@ class Website(models.Model):
|
||||
fuzzy_term = self._search_find_fuzzy_term(search_details, search)
|
||||
if fuzzy_term:
|
||||
count, results = self._search_exact(search_details, fuzzy_term, limit, order)
|
||||
if fuzzy_term == search:
|
||||
if fuzzy_term.lower() == search.lower():
|
||||
fuzzy_term = False
|
||||
else:
|
||||
count, results = self._search_exact(search_details, search, limit, order)
|
||||
|
||||
@@ -210,3 +210,15 @@ class TestAutoComplete(TransactionCase):
|
||||
self.assertEqual(1, suggestions['results_count'], "Text data contains one page with 'long url'")
|
||||
self.assertEqual(1, len(suggestions['results']), "Single result must be present")
|
||||
self.assertEqual(url, suggestions['results'][0]['website_url'], 'URL must not be truncated')
|
||||
|
||||
def test_06_case_insensitive_results(self):
|
||||
""" Tests an autocomplete with exact match and more than the maximum
|
||||
number of results.
|
||||
"""
|
||||
suggestions = self._autocomplete("Many")
|
||||
self.assertEqual(6, suggestions['results_count'], "Test data contains six pages with 'Many'")
|
||||
self.assertEqual(5, len(suggestions['results']), "Results must be limited to 5")
|
||||
self.assertFalse(suggestions['fuzzy_search'], "Expects an exact match")
|
||||
for result in suggestions['results']:
|
||||
self._check_highlight("many", result['name'])
|
||||
self._check_highlight("many", result['description'])
|
||||
|
||||
Reference in New Issue
Block a user