Skip to content

Commit

Permalink
Merge pull request #9 from aniversarioperu/haystack
Browse files Browse the repository at this point in the history
Haystack
  • Loading branch information
aniversarioperu committed Feb 20, 2015
2 parents 79437fa + 6b8c73f commit 17167b4
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
19 changes: 19 additions & 0 deletions manolo/apps/visitors/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from haystack.forms import HighlightedSearchForm


class ManoloForm(HighlightedSearchForm):
def search(self):
sqs = super(ManoloForm, self).search()

if not self.is_valid():
return self.no_query_found()

if not self.cleaned_data.get('q'):
return self.no_query_found()

sqs = self.searchqueryset.auto_query(self.cleaned_data['q']).order_by('-date')

if self.load_all:
sqs = sqs.load_all()

return sqs
2 changes: 1 addition & 1 deletion manolo/apps/visitors/search_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class VisitorIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
date = indexes.DateField(model_attr='date')
date = indexes.DateField(model_attr='date', null=True)

def get_model(self):
return Visitor
16 changes: 16 additions & 0 deletions manolo/apps/visitors/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,27 @@
from django.http import Http404
from haystack.query import SearchQuerySet

from visitors.forms import ManoloForm


def index(request):
return render(request, "index.html")


def search(request):
form = ManoloForm(request.GET)
query = request.GET['q']
all_items = form.search()
paginator, page = do_pagination(request, all_items)
return render(request, "search/search.html",
{
"paginator": paginator,
"page": page,
"query": query,
}
)


def search_date(request):
if 'q' in request.GET:
query = request.GET['q']
Expand Down
1 change: 1 addition & 0 deletions manolo/templates/search/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ <h4>Manolo es un buscador de personas que visitan entidades del Estado peruano</
<label class="sr-only" for="query">Keyword</label>
<input style="width:250px;" type="text" id="query" name="q"
class="form-control"
value="{{ query }}"
placeholder="Tipea persona o palabra clave">
</div>
<button type="submit" class="btn btn-info" id="search_button">
Expand Down
3 changes: 2 additions & 1 deletion manolo/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
url(r'^search_date/$', views.search_date),
url(r'^search/', include('haystack.urls')),
url(r'^search/', views.search, name='search_view'),
# url(r'^search/', include('haystack.urls')),
url(r'^$', include('visitors.urls', namespace="visitors")),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Expand Down
4 changes: 2 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

pyprind==2.9.1
Whoosh==2.6.0
psycopg2==2.5.4
psycopg2==2.6.0
Django==1.7.4
Jinja2==2.7.3
MarkupSafe==0.23
Expand All @@ -21,5 +21,5 @@ django-model-utils==2.2
docutils==0.12
python-slugify==0.1.0
six==1.9
elasticsearch==1.3.0
elasticsearch==1.4.0
wheel==0.24.0

0 comments on commit 17167b4

Please sign in to comment.