Search results are chronological

Also moved to search_view_factory because apparently it's thread-safe and I think Apache runs multiple threads.
This commit is contained in:
Matthias Portzel 2022-03-11 21:14:37 -05:00
parent e72d87415c
commit d81c8cbda1
2 changed files with 8 additions and 2 deletions

View File

@ -3,6 +3,7 @@ from .models import Thought
class ThoughtIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True, template_name="search/indexes/main/thought_text.txt")
posted = indexes.DateTimeField(model_attr="posted")
def get_model(self):
return Thought

View File

@ -5,7 +5,8 @@ from main import views
from main.feed import MainFeed
from whispermaphone import settings
from haystack.views import SearchView
from haystack.views import SearchView, search_view_factory
from haystack.query import SearchQuerySet
from haystack.forms import SearchForm
urlpatterns = [
@ -14,5 +15,9 @@ urlpatterns = [
path("login", views.login, name="login"),
path("post", views.post, name="post"),
path("feed", MainFeed()),
path("search", SearchView(form_class=SearchForm), name="thoughts_search")
path("search", search_view_factory(
view_class=SearchView,
form_class=SearchForm,
searchqueryset=SearchQuerySet().order_by("-posted")
), name="thoughts_search")
] + (static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) if settings.DEBUG else [])