From 3733a93cf37e23b3c8ad8fcac7af272504e09ecb Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 12 Feb 2013 17:02:40 +0100 Subject: [PATCH] search --- catalogue/search_indexes.py | 10 ++++++++ .../search/indexes/catalogue/lesson_text.txt | 1 + edumed/settings.d/30-apps.py | 2 ++ edumed/settings.d/35-search.py | 6 +++++ edumed/templates/base.html | 2 +- edumed/templates/search/search.html | 25 +++++++++++++++++++ edumed/urls.py | 1 + requirements.txt | 3 +++ 8 files changed, 49 insertions(+), 1 deletion(-) create mode 100755 catalogue/search_indexes.py create mode 100755 catalogue/templates/search/indexes/catalogue/lesson_text.txt create mode 100755 edumed/settings.d/35-search.py create mode 100755 edumed/templates/search/search.html diff --git a/catalogue/search_indexes.py b/catalogue/search_indexes.py new file mode 100755 index 0000000..3179efb --- /dev/null +++ b/catalogue/search_indexes.py @@ -0,0 +1,10 @@ +import datetime +from haystack import indexes +from .models import Lesson + + +class LessonIndex(indexes.SearchIndex, indexes.Indexable): + text = indexes.CharField(document=True, use_template=True) + + def get_model(self): + return Lesson diff --git a/catalogue/templates/search/indexes/catalogue/lesson_text.txt b/catalogue/templates/search/indexes/catalogue/lesson_text.txt new file mode 100755 index 0000000..ab6feff --- /dev/null +++ b/catalogue/templates/search/indexes/catalogue/lesson_text.txt @@ -0,0 +1 @@ +{{ object.html_file.read|striptags }} diff --git a/edumed/settings.d/30-apps.py b/edumed/settings.d/30-apps.py index db5d100..10c6c12 100644 --- a/edumed/settings.d/30-apps.py +++ b/edumed/settings.d/30-apps.py @@ -11,6 +11,8 @@ INSTALLED_APPS = ( # Disable, if not using CAS. 'django_cas', 'sponsors', + 'haystack', + 'django.contrib.auth', 'django.contrib.contenttypes', diff --git a/edumed/settings.d/35-search.py b/edumed/settings.d/35-search.py new file mode 100755 index 0000000..bfc6f28 --- /dev/null +++ b/edumed/settings.d/35-search.py @@ -0,0 +1,6 @@ +HAYSTACK_CONNECTIONS = { + 'default': { + 'ENGINE': 'haystack.backends.solr_backend.SolrEngine', + 'URL': 'http://127.0.0.1:8983/solr/edumed' + }, +} diff --git a/edumed/templates/base.html b/edumed/templates/base.html index ca28197..cda342f 100644 --- a/edumed/templates/base.html +++ b/edumed/templates/base.html @@ -52,7 +52,7 @@
Scenariusze zajęć, ćwiczenia, materiały
diff --git a/edumed/templates/search/search.html b/edumed/templates/search/search.html new file mode 100755 index 0000000..4216ab9 --- /dev/null +++ b/edumed/templates/search/search.html @@ -0,0 +1,25 @@ +{% extends "base.html" %} + +{% block body %} +

Wyszukiwanie

+ + {% if query %} + {% for result in page.object_list %} +

+ {{ result.object.title }} +

+ {% empty %} +

Brak wyników.

+ {% endfor %} + + {% if page.has_previous or page.has_next %} +
+ {% if page.has_previous %}{% endif %}« Poprzednie{% if page.has_previous %}{% endif %} + | + {% if page.has_next %}{% endif %}Następne »{% if page.has_next %}{% endif %} +
+ {% endif %} + {% else %} +

Brak wyników.

+ {% endif %} +{% endblock %} diff --git a/edumed/urls.py b/edumed/urls.py index 95748cd..5978ddf 100644 --- a/edumed/urls.py +++ b/edumed/urls.py @@ -12,6 +12,7 @@ urlpatterns = patterns('', # url(r'^i/', include('django.contrib.flatpages.urls')), url(r'^i/(?P.*)$', 'django.contrib.flatpages.views.flatpage', name="info"), + url(r'^szukaj/', include('haystack.urls')), ) diff --git a/requirements.txt b/requirements.txt index 6cbc8e1..32f519f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,3 +21,6 @@ lxml # sponsors pillow django-sponsors + +-e git+https://github.com/toastdriven/django-haystack.git@61b377d97efd5390c60c5a37acd009b8e69eb2f3#egg=django-haystack +pysolr>=2,<3 -- 2.20.1