# HG changeset patch # User Brian Neal # Date 1275770812 0 # Node ID 26ee684c20338bdd4706a88e2805fad4d18fb47f # Parent 6dbb8faef085e8e30874a78400827233a4ad3093 Initial commit of Haystack search integration. See #51. diff -r 6dbb8faef085 -r 26ee684c2033 gpp/news/search_indexes.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/news/search_indexes.py Sat Jun 05 20:46:52 2010 +0000 @@ -0,0 +1,16 @@ +"""Haystack search index for the news application.""" +from haystack.indexes import * +from haystack import site +from news.models import Story + + +class StoryIndex(SearchIndex): + text = CharField(document=True, use_template=True) + author = CharField(model_attr='submitter') + pub_date = DateTimeField(model_attr='date_submitted') + + title = CharField(use_template=True, indexed=False) + summary = CharField(use_template=True, indexed=False) + + +site.register(Story, StoryIndex) diff -r 6dbb8faef085 -r 26ee684c2033 gpp/search_sites.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/search_sites.py Sat Jun 05 20:46:52 2010 +0000 @@ -0,0 +1,2 @@ +import haystack +haystack.autodiscover() diff -r 6dbb8faef085 -r 26ee684c2033 gpp/settings.py --- a/gpp/settings.py Tue Jun 01 05:16:40 2010 +0000 +++ b/gpp/settings.py Sat Jun 05 20:46:52 2010 +0000 @@ -128,6 +128,7 @@ 'django.contrib.sites', 'elsewhere', 'tagging', + 'haystack', 'accounts', 'antispam', 'bio', @@ -201,6 +202,14 @@ MAX_TAG_LENGTH = 50 ####################################################################### +# Haystack Search Settings +####################################################################### +HAYSTACK_SITECONF = 'gpp.search_sites' +HAYSTACK_SEARCH_ENGINE = 'xapian' +HAYSTACK_XAPIAN_PATH = os.path.join(project_path, 'xapian_index') + + +####################################################################### # GPP Specific Settings ####################################################################### GPP_LOG_LEVEL = 0 diff -r 6dbb8faef085 -r 26ee684c2033 gpp/templates/base.html --- a/gpp/templates/base.html Tue Jun 01 05:16:40 2010 +0000 +++ b/gpp/templates/base.html Sat Jun 05 20:46:52 2010 +0000 @@ -41,6 +41,7 @@
  • Welcome, {{ user.username }}
  • Forums
  • {% unread_messages user %}
  • +
  • Search
  • Logout
  • {% else %}
  • Login
  • @@ -66,6 +67,7 @@
  • Photo of the Day
  • Links
  • Downloads
  • +
  • Search
  • {% cache 300 potd_block %} {% photo_of_the_day %} diff -r 6dbb8faef085 -r 26ee684c2033 gpp/templates/search/indexes/news/story_summary.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/templates/search/indexes/news/story_summary.txt Sat Jun 05 20:46:52 2010 +0000 @@ -0,0 +1,2 @@ +{{ object.short_text|safe }} +{{ object.long_text|safe }} diff -r 6dbb8faef085 -r 26ee684c2033 gpp/templates/search/indexes/news/story_text.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/templates/search/indexes/news/story_text.txt Sat Jun 05 20:46:52 2010 +0000 @@ -0,0 +1,6 @@ +{{ object.title }} +{{ object.submitter.username }} +{{ object.submitter.get_full_name }} +{{ object.short_text }} +{{ object.long_text }} +{{ object.tags }} diff -r 6dbb8faef085 -r 26ee684c2033 gpp/templates/search/indexes/news/story_title.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/templates/search/indexes/news/story_title.txt Sat Jun 05 20:46:52 2010 +0000 @@ -0,0 +1,1 @@ +{{ object.title }} diff -r 6dbb8faef085 -r 26ee684c2033 gpp/templates/search/search.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/templates/search/search.html Sat Jun 05 20:46:52 2010 +0000 @@ -0,0 +1,42 @@ +{% extends 'base.html' %} +{% load highlight %} +{% block title %}Search{% endblock %} +{% block content %} +

    Search Search

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

    Results

    + {% if page.object_list %} +
    + {% for result in page.object_list %} +
    + {{ result.verbose_name }}: {{ result.title|safe }} • {{ result.score }} +
    +
    + {% highlight result.summary with query css_class "highlight" max_length 200 %} +
    + {% endfor %} +
    + {% endif %} + + {% 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 -r 6dbb8faef085 -r 26ee684c2033 gpp/urls.py --- a/gpp/urls.py Tue Jun 01 05:16:40 2010 +0000 +++ b/gpp/urls.py Sat Jun 05 20:46:52 2010 +0000 @@ -3,6 +3,8 @@ from django.contrib import admin from django.views.decorators.cache import cache_page +from haystack.views import SearchView, search_view_factory + from news.feeds import LatestNewsFeed from forums.feeds import ForumsFeed @@ -45,6 +47,13 @@ (r'^smiley/', include('smiley.urls')), ) +# Haystack search views +urlpatterns += patterns('haystack.views', + url(r'^search/$', search_view_factory(view_class=SearchView, load_all=False), + name='haystack_search'), +) + + if settings.DEBUG: urlpatterns += patterns('', (r'^static/(?P.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), diff -r 6dbb8faef085 -r 26ee684c2033 media/icons/magnifier.png Binary file media/icons/magnifier.png has changed