mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
search: sort by User.last_update
This commit is contained in:
parent
30091ef69c
commit
a38ab57ddf
@ -34,6 +34,7 @@ from forum.models import ForumMessage, ForumMessageMeta
|
|||||||
class UserIndex(indexes.SearchIndex, indexes.Indexable):
|
class UserIndex(indexes.SearchIndex, indexes.Indexable):
|
||||||
text = indexes.CharField(document=True, use_template=True)
|
text = indexes.CharField(document=True, use_template=True)
|
||||||
auto = indexes.EdgeNgramField(use_template=True)
|
auto = indexes.EdgeNgramField(use_template=True)
|
||||||
|
last_update = indexes.DateTimeField(model_attr="last_update")
|
||||||
|
|
||||||
def get_model(self):
|
def get_model(self):
|
||||||
return User
|
return User
|
||||||
|
@ -75,12 +75,17 @@ def notification(request, notif_id):
|
|||||||
def search_user(query, as_json=False):
|
def search_user(query, as_json=False):
|
||||||
try:
|
try:
|
||||||
# slugify turns everything into ascii and every whitespace into -
|
# slugify turns everything into ascii and every whitespace into -
|
||||||
# it ends by removing duplicate - (so '- - ' will turn into '-')
|
# it ends by removing duplicate - (so ' - ' will turn into '-')
|
||||||
# replace('-', ' ') because search is whitespace based
|
# replace('-', ' ') because search is whitespace based
|
||||||
query = slugify(query).replace("-", " ")
|
query = slugify(query).replace("-", " ")
|
||||||
# is this necessary? it's not done when indexing users
|
# TODO: is this necessary?
|
||||||
query = html.escape(query)
|
query = html.escape(query)
|
||||||
res = SearchQuerySet().models(User).autocomplete(auto=query)[:20]
|
res = (
|
||||||
|
SearchQuerySet()
|
||||||
|
.models(User)
|
||||||
|
.autocomplete(auto=query)
|
||||||
|
.order_by("-last_update")[:20]
|
||||||
|
)
|
||||||
return [r.object for r in res]
|
return [r.object for r in res]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return []
|
return []
|
||||||
|
Loading…
Reference in New Issue
Block a user