Permalink
Browse files

Add search

  • Loading branch information...
norm committed Jul 22, 2015
1 parent 98fbda2 commit 832eb2db961fb79da678c4be884dfa850afb3dec
View
@@ -1 +1,2 @@
*.pyc
xapian_index
View
@@ -22,6 +22,29 @@ Setup the database tables:
python manage.py migrate
Search uses xapian, so that needs to be installed:
* On ubuntu:
sudo apt-get install python-xapian
* On OSX:
First install xapian.
brew install xapian
Then in the virtualenv, install the python xapian bindings for the
version of xapian you have installed.
XAPIAN_VERSION=1.2.19
wget http://oligarchy.co.uk/xapian/${XAPIAN_VERSION}/xapian-bindings-${XAPIAN_VERSION}.tar.xz
tar xJf xapian-bindings-${XAPIAN_VERSION}.tar.xz
cd xapian-bindings-${XAPIAN_VERSION}
./configure --with-python
make
sudo make install
Run the app:
honcho start
@@ -0,0 +1,11 @@
from haystack import indexes
from .models import Bookmark
class BookmarkIndex(indexes.SearchIndex, indexes.Indexable):
title = indexes.CharField(model_attr='title')
text = indexes.CharField(document=True, use_template=True)
def get_model(self):
return Bookmark
View
@@ -41,6 +41,7 @@
'apps.bookmarks',
'taggit',
'haystack',
)
MIDDLEWARE_CLASSES = (
@@ -110,3 +111,10 @@
STATIC_URL = '/static/'
TAGGIT_CASE_INSENSITIVE = True
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'xapian_backend.XapianEngine',
'PATH': os.path.join(os.path.dirname(__file__), 'xapian_index'),
},
}
View
@@ -83,4 +83,6 @@
TaggedList.as_view(),
name='tagged-list',
),
url(r'^search/', include('haystack.urls')),
]
View
@@ -2,3 +2,5 @@ Django==1.8.3
honcho==0.6.6
psycopg2==2.6.1
django-taggit==0.16.2
django-haystack==2.4.0
git+https://github.com/notanumber/xapian-haystack.git
@@ -0,0 +1,3 @@
{{object.title}}
{{object.description}}
{{object.url}}
@@ -0,0 +1,35 @@
<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>

0 comments on commit 832eb2d

Please sign in to comment.