I have django haystack 2.0.0 with whoosh setup like this
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
'PATH': '/home/kbuzz/whoosh_index',
'EXCLUDED_INDEXES': ['<movies.search_indexes.EventIndex object at 0x7f445fff0ef0>','<movies.search_indexes.EventIndex object at 0x7fd07ca3ef58>','<movies.search_indexes.EventIndex object at 0x7f0d2cfecf58>','<movies.search_indexes.EventIndex object at 0x7f990700bf58>'],
},
}
but rebuild_index and update_index doesn't work, clear_index works though.
I have search_indexes.py
for Article Model setup
import datetime
from haystack import indexes
from search.base_search_index import BaseSearchIndex
from articles.models import Article
and the BaseSearchIndex
import datetime
from django.db.models import Q
from haystack import indexes
class BaseSearchIndex(indexes.SearchIndex):
text = indexes.CharField(document=True, use_template=True)
html = indexes.CharField(use_template=True, indexed=False)
json = indexes.CharField(use_template=True, indexed=False)
slug = indexes.CharField()
#pk_xapian = indexes.IntegerField(model_attr='pk')
i = indexes.IntegerField(model_attr='pk')
def prepare_slug(self, obj):
return u'unique%sunique' % obj.slug
def get_updated_field(self):
return 'modified'
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
today = datetime.date.today()
return self.get_model().objects.filter(
Q(visible=True) &
Q(publish__lte=today) &
(Q(expires__isnull=True) | Q(expires__gte=today))
).distinct()
def prepare(self, obj):
today = datetime.datetime.now()
data = super(BaseSearchIndex, self).prepare(obj)
weeks = (today - obj.created).days / 7 + 1
data['boost'] = 1 + (1.0 / weeks)
return data
def get_list_for_multivalue_field(self, value):
if len(value) == 0:
return []
elif len(value) == 1:
return [value[0],]
return value
class ArticleIndex(BaseSearchIndex, indexes.Indexable):
area = indexes.IntegerField(null=True)
categories = indexes.MultiValueField(null=True)
hot = indexes.BooleanField(model_attr='is_hot')
def prepare_area(self, obj):
if obj.area_id:
return obj.area_id
return -1
def prepare_categories(self, obj):
cats = []
for category in obj.categories.all():
cats.extend([c.id for c in category.get_ancestors(include_self=True)])
return self.get_list_for_multivalue_field(cats)
def get_model(self):
return Article
with the Article model
class Article(BaseItemModel):
area = TreeForeignKey(Area, blank=True, null=True,)
categories = TreeManyToManyField(Category)
#imdb_id = models.CharField(max_length=255, blank=True, help_text="Used only for Series and Movie Reviews")
#tags = models.ManyToManyField(Tag, blank=True, null=True)
parent = models.ForeignKey(Movie, blank=True, verbose_name='Parent Movie', null=True, help_text="Used only for Series and Movie Reviews")
rating = models.IntegerField(blank=True, default=0)
editor_pick = models.BooleanField(default=False,)
author = models.CharField(max_length=255, blank=True,)
html = RichTextUploadingField(blank=True, null=True,)
#html_edited = RichTextUploadingField(blank=True, null=True,)
def share_content(self):
html = self.html
if not html:
html = self.content
return html.replace('"', "'").strip()
@models.permalink
def get_absolute_url(self):
return ('article_detail', (), {'slug': self.slug})
when I run update_index
I get this error message
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/kbuzz/lib/python2.7/haystack/management/commands/update_index.py", line 184, in handle
return super(Command, self).handle(*items, **options)
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/core/management/base.py", line 503, in handle
label_output = self.handle_label(label, **options)
File "/home/kbuzz/lib/python2.7/haystack/management/commands/update_index.py", line 210, in handle_label
self.update_backend(label, using)
File "/home/kbuzz/lib/python2.7/haystack/management/commands/update_index.py", line 256, in update_backend
do_update(backend, index, qs, start, end, total, self.verbosity)
File "/home/kbuzz/lib/python2.7/haystack/management/commands/update_index.py", line 78, in do_update
backend.update(index, current_qs)
File "/home/kbuzz/lib/python2.7/haystack/backends/whoosh_backend.py", line 189, in update
self.log.error(u"%s while preparing object for update" % e.__name__, exc_info=True, extra={
AttributeError: 'UnknownFieldError' object has no attribute '__name__'