diff --git a/core/search_indexes.py b/core/search_indexes.py index 86401eed..7bece290 100644 --- a/core/search_indexes.py +++ b/core/search_indexes.py @@ -107,6 +107,7 @@ class BigCharFieldIndex(indexes.CharField): class ForumMessageIndex(indexes.SearchIndex, indexes.Indexable): text = BigCharFieldIndex(document=True, use_template=True) auto = indexes.EdgeNgramField(use_template=True) + date = indexes.DateTimeField(model_attr="date") def get_model(self): return ForumMessage diff --git a/forum/views.py b/forum/views.py index 6289c42f..a1011c05 100644 --- a/forum/views.py +++ b/forum/views.py @@ -54,11 +54,17 @@ class ForumSearchView(ListView): def get_queryset(self): query = self.request.GET.get("query", "") + order_by = self.request.GET.get("order", "") + if query == "": return [] - queryset = ( - SearchQuerySet().models(ForumMessage).autocomplete(auto=query).load_all() - ) + + queryset = SearchQuerySet().models(ForumMessage).autocomplete(auto=query) + + if order_by == "date": + queryset.order_by("date") + + queryset = queryset.load_all() # Filter unauthorized responses resp = []