Skip to content
Snippets Groups Projects
Commit a6e08d3c authored by Bryan BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

allows to add integer field to index, prevent substring that are integer to be added

parent 054f6461
No related branches found
No related tags found
No related merge requests found
......@@ -80,7 +80,7 @@ def _add_instance_to_index(instance, field_names: List[str], objects: list, curs
if f and not f():
return
for field_name in field_names:
_add_text_to_index(getattr(instance, field_name), objects, cursor)
_add_text_to_index(str(getattr(instance, field_name)), objects, cursor)
def add_text_to_index(value: str):
......@@ -120,9 +120,10 @@ def _purge_banned_words():
def _add_text_to_index(value: str, objects: list, cursor):
if value is None or value == '':
return
len_value = len(value)
for word in split_string(value):
len_word = len(word)
if len_word < _AUTOCOMPLETE_MIN_LENGTH or word.isdecimal() or len_word > 64:
if len_word < _AUTOCOMPLETE_MIN_LENGTH or (len_word != len_value and word.isdecimal()) or len_word > 64:
continue
cursor.execute("SELECT UPPER(UNACCENT(%s)) as value", [word])
ac_word = cursor.fetchone()[0]
......
......@@ -135,6 +135,20 @@ class BannedWord(test_helpers.ChangeAutoCompleteSettingsTestCase):
self.assertEqual(models.IndexedWord.objects.count(), 3)
@override_settings(AUTOCOMPLETE_MIN_LENGTH=1)
class SubIntNotAdded(test_helpers.ChangeAutoCompleteSettingsTestCase):
def test_it(self):
business_process.add_text_to_index("00001101 AAAA ZZZZ EEEE")
self.assertEqual(models.IndexedWord.objects.count(), 3)
@override_settings(AUTOCOMPLETE_MIN_LENGTH=1)
class CompleteIntAdded(test_helpers.ChangeAutoCompleteSettingsTestCase):
def test_it(self):
business_process.add_text_to_index("0000110")
self.assertEqual(models.IndexedWord.objects.count(), 1)
@override_settings(AUTOCOMPLETE_PERSISTENT_VARIABLE_GETTER_SETTER=None)
class NeedRebuildDefaultBehaviorTestCase(test_helpers.ChangeAutoCompleteSettingsTestCase):
def test_it(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment