Add prototype of full text search integration in openslides
Allow for empty title and text body, fix pep8 errors
This commit is contained in:
parent
21da6c24a8
commit
95fe58eb99
12
openslides/agenda/search_indexes.py
Normal file
12
openslides/agenda/search_indexes.py
Normal 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)
|
@ -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')
|
||||||
|
4
openslides/search_sites.py
Normal file
4
openslides/search_sites.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import haystack
|
||||||
|
|
||||||
|
|
||||||
|
haystack.autodiscover()
|
39
openslides/templates/search/search.html
Normal file
39
openslides/templates/search/search.html
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>Search</h2>
|
||||||
|
|
||||||
|
<form method="get" action=".">
|
||||||
|
<table>
|
||||||
|
{{ form.as_table }}
|
||||||
|
<tr>
|
||||||
|
<td> </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 }}&page={{ page.previous_page_number }}">{% endif %}« Previous{% if page.has_previous %}</a>{% endif %}
|
||||||
|
|
|
||||||
|
{% if page.has_next %}<a href="?q={{ query }}&page={{ page.next_page_number }}">{% endif %}Next »{% if page.has_next %}</a>{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
{# Show some example queries to run, maybe query syntax, something else? #}
|
||||||
|
{% endif %}
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
@ -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': []}
|
||||||
|
Loading…
Reference in New Issue
Block a user