mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 06:03:20 +00:00
core: improve search index with 'autocomplete'
This commit is contained in:
parent
65e0b15b31
commit
aba4207423
@ -31,6 +31,7 @@ from core.models import User
|
||||
|
||||
class UserIndex(indexes.SearchIndex, indexes.Indexable):
|
||||
text = indexes.CharField(document=True, use_template=True)
|
||||
auto = indexes.EdgeNgramField(use_template=True)
|
||||
|
||||
def get_model(self):
|
||||
return User
|
||||
|
3
core/templates/search/indexes/core/user_auto.txt
Normal file
3
core/templates/search/indexes/core/user_auto.txt
Normal file
@ -0,0 +1,3 @@
|
||||
{{ object.first_name }}
|
||||
{{ object.last_name }}
|
||||
{{ object.nick_name }}
|
@ -71,7 +71,7 @@ def notification(request, notif_id):
|
||||
|
||||
|
||||
def search_user(query, as_json=False):
|
||||
res = SearchQuerySet().models(User).filter_or(text__contains=query)[:20]
|
||||
res = SearchQuerySet().models(User).autocomplete(auto=query)[:20]
|
||||
return [r.object for r in res]
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user