Working on search

master
Nick Sergeant 2012-04-17 00:42:01 -04:00
parent 94db0dd3c9
commit 22d6a3d2cd
6 changed files with 76 additions and 0 deletions

View File

@ -14,6 +14,7 @@ johnny-cache
lxml
psycopg2
Pygments
pysolr
python-memcached
python-postmark
pyyaml
@ -22,5 +23,6 @@ uuid
versiontools
Werkzeug
git+https://github.com/toastdriven/django-haystack.git@master#egg=django-haystack
hg+https://bitbucket.org/ubernostrum/django-registration#egg=django-registration
git+https://github.com/toastdriven/django-tastypie.git#egg=django-tastypie

View File

@ -143,6 +143,7 @@ INSTALLED_APPS = (
'compressor',
'django_bcrypt',
'haystack',
'pagination',
'postmark',
'registration',
@ -234,6 +235,14 @@ COMPRESS_PRECOMPILERS = (
('text/x-scss', 'sass --scss {infile} {outfile}'),
)
# Search
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
'URL': 'http://127.0.0.1:8983/solr'
},
}
# Extensions
if DEBUG:
INSTALLED_APPS += ('django_extensions',)

18
snipts/search_indexes.py Normal file
View File

@ -0,0 +1,18 @@
import datetime
from haystack import indexes
from snipts.models import Snipt
class SniptIndex(indexes.RealTimeSearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
author = indexes.CharField(model_attr='user')
pub_date = indexes.DateTimeField(model_attr='created')
public = indexes.BooleanField(model_attr='public')
typ = indexes.CharField(model_attr='lexer')
def get_model(self):
return Snipt
def index_queryset(self):
"""Used when the entire index for model is updated."""
return self.get_model().objects.filter(created__lte=datetime.datetime.now())

View File

@ -0,0 +1,5 @@
{{ object.title }}
{{ object.user.username }}
{{ object.tags_list }}
{{ object.lexer }}
{{ object.code }}

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

@ -8,6 +8,7 @@ from snipts.api import *
import admin as custom_admin
admin.autodiscover()
public_api = Api(api_name='public')
@ -35,6 +36,8 @@ urlpatterns = patterns('',
url(r'^api/', include(public_api.urls)),
url(r'^api/', include(private_api.urls)),
url(r'^search/', include('haystack.urls')),
url(r'^register/$', lambda x: HttpResponseRedirect('/signup/')),
url(r'^signup/$',
'registration.views.register', {