Working on search
parent
94db0dd3c9
commit
22d6a3d2cd
|
@ -14,6 +14,7 @@ johnny-cache
|
||||||
lxml
|
lxml
|
||||||
psycopg2
|
psycopg2
|
||||||
Pygments
|
Pygments
|
||||||
|
pysolr
|
||||||
python-memcached
|
python-memcached
|
||||||
python-postmark
|
python-postmark
|
||||||
pyyaml
|
pyyaml
|
||||||
|
@ -22,5 +23,6 @@ uuid
|
||||||
versiontools
|
versiontools
|
||||||
Werkzeug
|
Werkzeug
|
||||||
|
|
||||||
|
git+https://github.com/toastdriven/django-haystack.git@master#egg=django-haystack
|
||||||
hg+https://bitbucket.org/ubernostrum/django-registration#egg=django-registration
|
hg+https://bitbucket.org/ubernostrum/django-registration#egg=django-registration
|
||||||
git+https://github.com/toastdriven/django-tastypie.git#egg=django-tastypie
|
git+https://github.com/toastdriven/django-tastypie.git#egg=django-tastypie
|
||||||
|
|
|
@ -143,6 +143,7 @@ INSTALLED_APPS = (
|
||||||
|
|
||||||
'compressor',
|
'compressor',
|
||||||
'django_bcrypt',
|
'django_bcrypt',
|
||||||
|
'haystack',
|
||||||
'pagination',
|
'pagination',
|
||||||
'postmark',
|
'postmark',
|
||||||
'registration',
|
'registration',
|
||||||
|
@ -234,6 +235,14 @@ COMPRESS_PRECOMPILERS = (
|
||||||
('text/x-scss', 'sass --scss {infile} {outfile}'),
|
('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
|
# Extensions
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
INSTALLED_APPS += ('django_extensions',)
|
INSTALLED_APPS += ('django_extensions',)
|
||||||
|
|
|
@ -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())
|
|
@ -0,0 +1,5 @@
|
||||||
|
{{ object.title }}
|
||||||
|
{{ object.user.username }}
|
||||||
|
{{ object.tags_list }}
|
||||||
|
{{ object.lexer }}
|
||||||
|
{{ object.code }}
|
|
@ -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 %}
|
3
urls.py
3
urls.py
|
@ -8,6 +8,7 @@ from snipts.api import *
|
||||||
|
|
||||||
import admin as custom_admin
|
import admin as custom_admin
|
||||||
|
|
||||||
|
|
||||||
admin.autodiscover()
|
admin.autodiscover()
|
||||||
|
|
||||||
public_api = Api(api_name='public')
|
public_api = Api(api_name='public')
|
||||||
|
@ -35,6 +36,8 @@ urlpatterns = patterns('',
|
||||||
url(r'^api/', include(public_api.urls)),
|
url(r'^api/', include(public_api.urls)),
|
||||||
url(r'^api/', include(private_api.urls)),
|
url(r'^api/', include(private_api.urls)),
|
||||||
|
|
||||||
|
url(r'^search/', include('haystack.urls')),
|
||||||
|
|
||||||
url(r'^register/$', lambda x: HttpResponseRedirect('/signup/')),
|
url(r'^register/$', lambda x: HttpResponseRedirect('/signup/')),
|
||||||
url(r'^signup/$',
|
url(r'^signup/$',
|
||||||
'registration.views.register', {
|
'registration.views.register', {
|
||||||
|
|
Loading…
Reference in New Issue