From 95fe58eb99341974c79f1ea83fedaf5c7bed45a9 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Sun, 28 Apr 2013 18:38:17 +0200 Subject: [PATCH] Add prototype of full text search integration in openslides Allow for empty title and text body, fix pep8 errors --- openslides/agenda/search_indexes.py | 12 ++++++++ openslides/global_settings.py | 9 ++++++ openslides/search_sites.py | 4 +++ openslides/templates/search/search.html | 39 +++++++++++++++++++++++++ openslides/urls.py | 1 + 5 files changed, 65 insertions(+) create mode 100644 openslides/agenda/search_indexes.py create mode 100644 openslides/search_sites.py create mode 100644 openslides/templates/search/search.html diff --git a/openslides/agenda/search_indexes.py b/openslides/agenda/search_indexes.py new file mode 100644 index 000000000..c4af565fb --- /dev/null +++ b/openslides/agenda/search_indexes.py @@ -0,0 +1,12 @@ +import datetime +from haystack.indexes import * +from haystack import site +from openslides.agenda.models import Item + + +class AgendaIndex(RealTimeSearchIndex): + title = CharField(model_attr='title', null=True) + text = CharField(document=True, model_attr='text', null=True) + + +site.register(Item, AgendaIndex) diff --git a/openslides/global_settings.py b/openslides/global_settings.py index 9c2baea72..9b47a2d9a 100644 --- a/openslides/global_settings.py +++ b/openslides/global_settings.py @@ -118,6 +118,9 @@ INSTALLED_APPS = ( 'openslides.participant', 'openslides.mediafile', 'openslides.config', + + # full-text-search + 'haystack', ) TEMPLATE_CONTEXT_PROCESSORS = ( @@ -142,3 +145,9 @@ TEST_DISCOVER_TOP_LEVEL = os.path.dirname(os.path.dirname(__file__)) # Hosts/domain names that are valid for this site; required if DEBUG is False # See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts ALLOWED_HOSTS = ['*'] + + +# Full-text search +HAYSTACK_SITECONF = 'openslides.search_sites' +HAYSTACK_SEARCH_ENGINE = 'whoosh' +HAYSTACK_WHOOSH_PATH = os.path.join(os.path.dirname(__file__), 'whoosh_index') diff --git a/openslides/search_sites.py b/openslides/search_sites.py new file mode 100644 index 000000000..a3653e8fd --- /dev/null +++ b/openslides/search_sites.py @@ -0,0 +1,4 @@ +import haystack + + +haystack.autodiscover() diff --git a/openslides/templates/search/search.html b/openslides/templates/search/search.html new file mode 100644 index 000000000..566f1c405 --- /dev/null +++ b/openslides/templates/search/search.html @@ -0,0 +1,39 @@ +{% extends 'base.html' %} + +{% block content %} +

Search

+ +
+ + {{ form.as_table }} + + + + +
  + +
+ + {% if query %} +

Results

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

+ {{ result.object.title }} +

+ {% empty %} +

No results found.

+ {% endfor %} + + {% if page.has_previous or page.has_next %} +
+ {% if page.has_previous %}{% endif %}« Previous{% if page.has_previous %}{% endif %} + | + {% if page.has_next %}{% endif %}Next »{% if page.has_next %}{% endif %} +
+ {% endif %} + {% else %} + {# Show some example queries to run, maybe query syntax, something else? #} + {% endif %} +
+{% endblock %} diff --git a/openslides/urls.py b/openslides/urls.py index 776d3c860..88d8f9088 100644 --- a/openslides/urls.py +++ b/openslides/urls.py @@ -26,6 +26,7 @@ urlpatterns = patterns( (r'^config/', include('openslides.config.urls')), (r'^projector/', include('openslides.projector.urls')), (r'^i18n/', include('django.conf.urls.i18n')), + (r'^search/', include('haystack.urls')), ) js_info_dict = {'packages': []}