search
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Tue, 12 Feb 2013 16:02:40 +0000 (17:02 +0100)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Wed, 13 Feb 2013 08:57:11 +0000 (09:57 +0100)
catalogue/search_indexes.py [new file with mode: 0755]
catalogue/templates/search/indexes/catalogue/lesson_text.txt [new file with mode: 0755]
edumed/settings.d/30-apps.py
edumed/settings.d/35-search.py [new file with mode: 0755]
edumed/templates/base.html
edumed/templates/search/search.html [new file with mode: 0755]
edumed/urls.py
requirements.txt

diff --git a/catalogue/search_indexes.py b/catalogue/search_indexes.py
new file mode 100755 (executable)
index 0000000..3179efb
--- /dev/null
@@ -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 (executable)
index 0000000..ab6feff
--- /dev/null
@@ -0,0 +1 @@
+{{ object.html_file.read|striptags }}
index db5d100..10c6c12 100644 (file)
@@ -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 (executable)
index 0000000..bfc6f28
--- /dev/null
@@ -0,0 +1,6 @@
+HAYSTACK_CONNECTIONS = {
+    'default': {
+        'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
+        'URL': 'http://127.0.0.1:8983/solr/edumed'
+    },
+}
index ca28197..cda342f 100644 (file)
@@ -52,7 +52,7 @@
 
             <div id="tagline">Scenariusze zajęć, ćwiczenia, materiały</div>
             <div id="search">
-                <form action="">
+                <form action="{% url 'haystack_search' %}">
                     <input name="q" placeholder="szukaj" /><button><span>&rarr;</span></button>
                 </form>
             </div>
diff --git a/edumed/templates/search/search.html b/edumed/templates/search/search.html
new file mode 100755 (executable)
index 0000000..4216ab9
--- /dev/null
@@ -0,0 +1,25 @@
+{% extends "base.html" %}
+
+{% block body %}
+    <h1>Wyszukiwanie</h1>
+
+    {% if query %}
+        {% for result in page.object_list %}
+            <p>
+                <a href="{{ result.object.get_absolute_url }}">{{ result.object.title }}</a>
+            </p>
+        {% empty %}
+            <p>Brak wyników.</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; Poprzednie{% if page.has_previous %}</a>{% endif %}
+                |
+                {% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}Następne &raquo;{% if page.has_next %}</a>{% endif %}
+            </div>
+        {% endif %}
+    {% else %}
+        <p>Brak wyników.</p>
+    {% endif %}
+{% endblock %}
index 95748cd..5978ddf 100644 (file)
@@ -12,6 +12,7 @@ urlpatterns = patterns('',
 #    url(r'^i/', include('django.contrib.flatpages.urls')),
     url(r'^i/(?P<url>.*)$', 'django.contrib.flatpages.views.flatpage',
         name="info"),
+    url(r'^szukaj/', include('haystack.urls')),
 )
 
 
index 6cbc8e1..32f519f 100644 (file)
@@ -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