Add Whoosh index

This commit is contained in:
Skia 2016-12-19 19:58:51 +01:00 committed by Skia
parent ac31c182c5
commit 5b95299bde
6 changed files with 34 additions and 1 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ doc/html
data/ data/
static/ static/
sith/settings_custom.py sith/settings_custom.py
sith/whoosh_index/

View File

@ -190,7 +190,7 @@ class User(AbstractBaseUser):
return reverse('core:user_profile', kwargs={'user_id': self.pk}) return reverse('core:user_profile', kwargs={'user_id': self.pk})
def __str__(self): def __str__(self):
return self.username return self.get_display_name()
def to_dict(self): def to_dict(self):
return self.__dict__ return self.__dict__

19
core/search_indexes.py Normal file
View File

@ -0,0 +1,19 @@
from haystack import indexes
from core.models import User
class UserIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
def get_model(self):
return User
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().objects.all()
def prepare(self, obj):
ret = super(UserIndex, self).prepare(obj)
print(ret)
return ret

View File

@ -0,0 +1,3 @@
{{ object.get_display_name|safe }}
{{ object.get_display_name|safe|slugify }}
{{ object.get_display_name|safe|slugify|cut:"-" }}

View File

@ -9,5 +9,7 @@ djangorestframework
django-phonenumber-field django-phonenumber-field
django-ajax-selects django-ajax-selects
reportlab reportlab
django-haystack
whoosh
# mysqlclient # mysqlclient

View File

@ -46,6 +46,7 @@ INSTALLED_APPS = (
'django_jinja', 'django_jinja',
'rest_framework', 'rest_framework',
'ajax_select', 'ajax_select',
'haystack',
'core', 'core',
'club', 'club',
'subscription', 'subscription',
@ -142,6 +143,13 @@ TEMPLATES = [
}, },
] ]
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'),
},
}
WSGI_APPLICATION = 'sith.wsgi.application' WSGI_APPLICATION = 'sith.wsgi.application'