Skip to content

Commit

Permalink
Step26: full text search using django haystack
Browse files Browse the repository at this point in the history
  • Loading branch information
yangxg committed Jun 15, 2017
1 parent 27fae6f commit b888e01
Show file tree
Hide file tree
Showing 10 changed files with 1,002 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ ENV/

database/
media/
whoosh_index/
.idea/
*.sqlite3
fabfile.py
12 changes: 12 additions & 0 deletions blog/search_indexes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from haystack import indexes
from .models import Post


class PostIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)

def get_model(self):
return Post

def index_queryset(self, using=None):
return self.get_model().objects.all()
2 changes: 1 addition & 1 deletion blog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
url(r'^archives/(?P<year>[0-9]{4})/(?P<month>[0-9]{1,2})/$', views.ArchivesView.as_view(), name='archives'),
url(r'^category/(?P<pk>[0-9]+)/$', views.CategoryView.as_view(), name='category'),
url(r'^tag/(?P<pk>[0-9]+)/$', views.TagView.as_view(), name='tag'),
url(r'^search/$', views.search, name='search'),
# url(r'^search/$', views.search, name='search'),
]
2 changes: 2 additions & 0 deletions blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ def get_queryset(self):
return super(TagView, self).get_queryset().filter(tags=tag)


"""
def search(request):
q = request.GET.get('q')
error_msg = ''
Expand All @@ -311,3 +312,4 @@ def search(request):
post_list = Post.objects.filter(Q(title__icontains=q) | Q(body__icontains=q))
return render(request, 'blog/index.html', {'error_msg': error_msg,
'post_list': post_list})
"""
Loading

0 comments on commit b888e01

Please sign in to comment.