Add prototype of full text search integration in openslides

Allow for empty title and text body, fix pep8 errors
This commit is contained in:
Roland Geider 2013-04-28 18:38:17 +02:00 committed by Emanuel Schuetze
parent 21da6c24a8
commit 95fe58eb99
5 changed files with 65 additions and 0 deletions

View File

@ -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)

View File

@ -118,6 +118,9 @@ INSTALLED_APPS = (
'openslides.participant', 'openslides.participant',
'openslides.mediafile', 'openslides.mediafile',
'openslides.config', 'openslides.config',
# full-text-search
'haystack',
) )
TEMPLATE_CONTEXT_PROCESSORS = ( 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 # 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 # See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
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')

View File

@ -0,0 +1,4 @@
import haystack
haystack.autodiscover()

View File

@ -0,0 +1,39 @@
{% extends 'base.html' %}
{% block content %}
<h2>Search</h2>
<form method="get" action=".">
<table>
{{ form.as_table }}
<tr>
<td>&nbsp;</td>
<td>
<input type="submit" value="Search">
</td>
</tr>
</table>
{% if query %}
<h3>Results</h3>
{% for result in page.object_list %}
<p>
<a href="{{ result.object.get_absolute_url }}">{{ result.object.title }}</a>
</p>
{% empty %}
<p>No results found.</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; Previous{% if page.has_previous %}</a>{% endif %}
|
{% if page.has_next %}<a href="?q={{ query }}&amp;page={{ page.next_page_number }}">{% endif %}Next &raquo;{% if page.has_next %}</a>{% endif %}
</div>
{% endif %}
{% else %}
{# Show some example queries to run, maybe query syntax, something else? #}
{% endif %}
</form>
{% endblock %}

View File

@ -26,6 +26,7 @@ urlpatterns = patterns(
(r'^config/', include('openslides.config.urls')), (r'^config/', include('openslides.config.urls')),
(r'^projector/', include('openslides.projector.urls')), (r'^projector/', include('openslides.projector.urls')),
(r'^i18n/', include('django.conf.urls.i18n')), (r'^i18n/', include('django.conf.urls.i18n')),
(r'^search/', include('haystack.urls')),
) )
js_info_dict = {'packages': []} js_info_dict = {'packages': []}