Commit 94fcbe85 authored by fred's avatar fred

add a search form (using django-haystack and solr)

parent 3d6319b4
from haystack import indexes
from .models import Emission, Episode
class EmissionIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
def get_model(self):
return Emission
class EpisodeIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
def get_model(self):
return Episode
{{ object.title }}
{{ object.description|striptags }}
{{ object.text|striptags }}
{{ object.title }}
{{ object.description|striptags }}
{{ object.text|striptags }}
...@@ -122,6 +122,7 @@ INSTALLED_APPS = ( ...@@ -122,6 +122,7 @@ INSTALLED_APPS = (
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django.contrib.admin', 'django.contrib.admin',
'ckeditor', 'ckeditor',
'haystack',
'panikdb.emissions', 'panikdb.emissions',
) )
...@@ -160,6 +161,12 @@ CKEDITOR_CONFIGS = { ...@@ -160,6 +161,12 @@ CKEDITOR_CONFIGS = {
}, },
} }
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
'URL': 'http://127.0.0.1:8080/solr'
},
}
try: try:
from local_settings import * from local_settings import *
......
{% extends 'panikdb/base.html' %}
{% block content %}
<h2>Recherche</h2>
<form method="get" action=".">
<table>
{{ form.as_table }}
<tr>
<td>&nbsp;</td>
<td>
<input type="submit" value="Rechercher">
</td>
</tr>
</table>
{% if query %}
<h3>Résultats</h3>
{% for result in page.object_list %}
<p>
<a href="{{ result.object.get_absolute_url }}">{{ result.object.title }}</a>
</p>
{% empty %}
<p>Aucun résultat trouvé.</p>
{% endfor %}
{% if page.has_previous or page.has_next %}
<div>
{% if page.has_previous %}<a href="?q={{ query }}&amp;page={{ page.previous_page_number }}">{% endif %}&laquo; Précédente{% if page.has_previous %}</a>{% endif %}
|
{% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}Suvante &raquo;{% if page.has_next %}</a>{% endif %}
</div>
{% endif %}
{% else %}
{# Show some example queries to run, maybe query syntax, something else? #}
{% endif %}
</form>
{% endblock %}
...@@ -3,9 +3,13 @@ from django.conf.urls import patterns, include, url ...@@ -3,9 +3,13 @@ from django.conf.urls import patterns, include, url
from django.contrib import admin from django.contrib import admin
admin.autodiscover() admin.autodiscover()
from haystack.views import SearchView, search_view_factory
from haystack.forms import SearchForm
urlpatterns = patterns('', urlpatterns = patterns('',
# url(r'^$', 'panikdb.views.home', name='home'), # url(r'^$', 'panikdb.views.home', name='home'),
(r'^ckeditor/', include('ckeditor.urls')), (r'^ckeditor/', include('ckeditor.urls')),
url(r'^search/', search_view_factory(view_class=SearchView, form_class=SearchForm), name='haystack_search'),
url(r'^panikdb/', include('panikdb.emissions.urls')), url(r'^panikdb/', include('panikdb.emissions.urls')),
url(r'^admin/', include(admin.site.urls)), url(r'^admin/', include(admin.site.urls)),
......
Django<1.6 Django<1.6
django-ckeditor django-ckeditor
git+https://github.com/toastdriven/django-haystack.git
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