Commit 55783456 authored by fred's avatar fred

add facet search

parent 107f7599
......@@ -5,10 +5,13 @@ from .models import Emission, Episode
class EmissionIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
categories = indexes.MultiValueField(faceted=True)
def get_model(self):
return Emission
def prepare_categories(self, obj):
return [category.title for category in obj.categories.all()]
class EpisodeIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
......
......@@ -15,8 +15,23 @@
</table>
{% if query %}
<!-- Begin faceting. -->
<p>
{% if facets.fields.categories %}
{# Provide only the top 5 authors #}
{% for category in facets.fields.categories|slice:":5" %}
<span><a href="{{ request.get_full_path }}&amp;selected_facets=categories_exact:{{ category.0|urlencode }}">{{ category.0 }}</a> ({{ category.1 }})</span>
{% endfor %}
{% else %}
No categories facets.
{% endif %}
</p>
<!-- End faceting -->
<h3>Résultats</h3>
{% for result in page.object_list %}
<p>
<a href="{{ result.object.get_absolute_url }}">{{ result.object.title }}</a>
......
......@@ -4,13 +4,17 @@ from django.conf import settings
from django.contrib import admin
admin.autodiscover()
from haystack.views import SearchView, search_view_factory
from haystack.forms import SearchForm
from haystack.views import FacetedSearchView, search_view_factory
from haystack.forms import FacetedSearchForm
from haystack.query import SearchQuerySet
sqs = SearchQuerySet().facet('categories')
urlpatterns = patterns('',
# url(r'^$', 'panikdb.views.home', name='home'),
(r'^ckeditor/', include('ckeditor.urls')),
url(r'^search/', search_view_factory(view_class=SearchView, form_class=SearchForm), name='haystack_search'),
url(r'^search/', search_view_factory(view_class=FacetedSearchView,
form_class=FacetedSearchForm, searchqueryset=sqs), name='haystack_search'),
url(r'^emissions/', include('panikdb.emissions.urls')),
url(r'^admin/', include(admin.site.urls)),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment