add leading word matches, fixes #2663

This commit is contained in:
j 2015-02-06 15:16:41 +05:30
parent ef3a7b720f
commit b5212f2662

View file

@ -130,12 +130,15 @@ def autocompleteEntities(request, data):
value_lower = data['value'].lower()
matches = []
leading_matches = []
leading_word_matches = []
for v in [e.name for e in qs]:
if v.lower().startswith(value_lower):
leading_matches.append(v)
elif [w for w in v.lower().split(' ') if w.strip().startswith(value_lower)]:
leading_word_matches.append(v)
else:
matches.append(v)
values = leading_matches + matches
values = leading_matches + leading_word_matches + matches
else:
values = [e.name for e in qs]
values = values[data['range'][0]:data['range'][1]]