Skip to content

Commit bd34696

Browse files
committed
almost done with the search feature. I had to do a fork of haystack development version though. Still need for work on testing, app_skeleton and documentation.
1 parent 9a17e5a commit bd34696

File tree

8 files changed

+55
-21
lines changed

8 files changed

+55
-21
lines changed

djity/project_skeleton/local_settings.py_tmpl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ DATABASES = {{
2525
}}
2626
}}
2727

28-
# Haystack search engine backend configuration, see:
29-
# http://docs.haystacksearch.org/dev/tutorial.html
30-
HAYSTACK_SEARCH_ENGINE = 'whoosh'
31-
HAYSTACK_WHOOSH_PATH = '%s/data/whoosh/djity_index' % PROJECT_ROOT
32-
3328
# in order to activate the django debug toolbar you will need to have it
3429
# installed: 'pip install django-debug-toolbar'
3530
DEBUG = {develop!r}

djity/project_skeleton/settings.py_tmpl

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ ADMIN_MEDIA_PREFIX = '/media/'
5757

5858
DAJAXICE_MEDIA_PREFIX="dajaxice" # Will create http://yourdomain.com/dajaxice/...
5959

60-
# Haystack configuration
61-
HAYSTACK_SITECONF = 'search_sites'
62-
6360
# Make this unique, and don't share it with anybody.
6461
SECRET_KEY = '{secret_key}'
6562

@@ -125,6 +122,7 @@ INSTALLED_APPS = [
125122
'djity.project',
126123
'djity.simplepage',
127124
'djity.transmeta',
125+
'djity.search',
128126
]
129127

130128
###########################################
@@ -208,6 +206,34 @@ LOCALE_INDEPENDENT_PATHS = (
208206

209207
FIXTURE_DIRS = 'data/fixtures'
210208

209+
###########################
210+
# Djity indexing settings #
211+
###########################
212+
213+
# Haystack search engine connections configuration
214+
HAYSTACK_CONNECTIONS = {{'default':{{
215+
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
216+
'PATH': '%s/data/whoosh/djity_index/default' % (PROJECT_ROOT),
217+
'STORAGE': 'file',
218+
'POST_LIMIT': 128 * 1024 * 1024,
219+
'INCLUDE_SPELLING': True,
220+
'BATCH_SIZE': 100,
221+
}}
222+
}}
223+
224+
for (language,language_repr) in LANGUAGES:
225+
HAYSTACK_CONNECTIONS['default_'+language] = {{
226+
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
227+
'PATH': '%s/data/whoosh/djity_index/%s' % (PROJECT_ROOT,language),
228+
'STORAGE': 'file',
229+
'POST_LIMIT': 128 * 1024 * 1024,
230+
'INCLUDE_SPELLING': True,
231+
'BATCH_SIZE': 100,
232+
'LANGUAGE': '%s' % language
233+
}}
234+
235+
HAYSTACK_ROUTERS = ['haystack.routers.LanguageRouter']
236+
211237
###################################################################
212238
# Import local settings and those from djity apps #
213239
###################################################################

djity/search/templatetags/__init__.py

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from django import template
2+
3+
register = template.Library()
4+
5+
@register.simple_tag(takes_context=True)
6+
def search_result(context, result):
7+
"""
8+
Will render a search result for haystack by using the appropriate template for each model type
9+
"""
10+
return template.loader.render_to_string("djity/%s/%s_search_result.html" % (result.app_label,result.model_name), {'result_url':result.object.djity_url(context)}, context)
11+

djity/search/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ def project_search(request,context=None):
1010
Override haystack basic_view for customization
1111
"""
1212
sqs = SearchQuerySet().filter(project=context['project'])
13+
#sqs = SearchQuerySet()
1314
return basic_search(request, template='djity/search/search.html', searchqueryset=sqs, extra_context=context, context_class=DjityContext)

djity/simplepage/search_indexes.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
from haystack.indexes import *
2-
from haystack import site
1+
from haystack import indexes
32

43
from djity.simplepage.models import SimplePage
54

6-
class SimplePageIndex(SearchIndex):
7-
text = CharField(document=True, model_attr='content')
8-
project = CharField(model_attr='project')
5+
class SimplePageIndex(indexes.SearchIndex, indexes.Indexable):
6+
text = indexes.CharField(document=True, model_attr='content')
7+
project = indexes.CharField(model_attr='project')
98

10-
site.register(SimplePage, SimplePageIndex)
11-
12-
class SimplePageIndex2(SearchIndex):
13-
text = CharField(document=True, model_attr='content')
14-
project = CharField(model_attr='project')
15-
16-
site.register(SimplePage, SimplePageIndex2)
9+
def get_model(self):
10+
return SimplePage

djity/templates/djity/search/search.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{% extends "djity/base.html" %}
22

3+
{% load search_result %}
4+
35
{% block body %}
46
<h2>Search</h2>
57

@@ -19,7 +21,7 @@ <h3>Results</h3>
1921

2022
{% for result in page.object_list %}
2123
<p>
22-
<a href="{{ result.object.get_absolute_url }}">{{ result.object.title }}</a>
24+
{% search_result result %}
2325
</p>
2426
{% empty %}
2527
<p>No results found.</p>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% load highlight %}
2+
3+
<a href="{{ result_url }}">{{ result.object.name }}</a><br>
4+
{% highlight result.object.content with query %}
5+

0 commit comments

Comments
 (0)