forum: make search fuzzy

This commit is contained in:
Antoine Bartuccio 2018-12-05 17:56:09 +01:00 committed by Skia
parent 286ba91c75
commit 404b825de4
3 changed files with 6 additions and 1 deletions

View File

@ -59,6 +59,7 @@ class UserOnlySignalProcessor(signals.BaseSignalProcessor):
class ForumMessageIndex(indexes.SearchIndex, indexes.Indexable): class ForumMessageIndex(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)
def get_model(self): def get_model(self):
return ForumMessage return ForumMessage

View File

@ -0,0 +1,4 @@
{{ object.topic }}
{{ object.title }}
{{ object.message }}
{{ object.author }}

View File

@ -47,7 +47,7 @@ class ForumSearchView(ListView):
def get_queryset(self): def get_queryset(self):
query = self.request.GET.get("query", "") query = self.request.GET.get("query", "")
q = SearchQuerySet().models(ForumMessage).filter_or(text__contains=query) q = SearchQuerySet().models(ForumMessage).autocomplete(auto=query)
return [r.object for r in q] return [r.object for r in q]