I am trying to set up django-haystack using whoosh as engine. My problem happens while building my first index as explained here.
Given my staff/models.py:
class Person(models.Model):
first_name = models.CharField(_('first name'), max_length=30, blank=True)
last_name = models.CharField(_('last name'), max_length=30, blank=True)
def __unicode__(self):
return '%s %s' % ( self.first_name, self.last_name)
I have written my staff/indexes.py:
from haystack import indexes
from staff.models import Person
class PersonIndex(indexes.SearchIndex, indexes.Indexable):
first_name = indexes.CharField(model_attr='first_name')
last_name = indexes.CharField(document=True, model_attr='last_name')
def get_model(self):
return Person
Then I have added the following configuration to my mycms/settings.py, to use whoosh as engine:
import os
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'),
},
}
The latter is taken word by word from the tutorial. Then I have added a simple text template for my index, mycms/templates/search/indexes/staff/person_text.txt
{{ object.first_name }}
{{ object.last_name }}
...updated my urlconf:
(r'^search/', include('haystack.urls')),
...and created my initial search template, which is copied from the tutorial:
{% 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 %}
Finally, following the steps in the tutorial, I have tried to build my first index. Then is when I'm getting the following error:
$ python manage.py rebuild_index
/home/roberto/.virtualenvs/ve_master/local/lib/python2.7/site-packages/mptt/models.py:305: DeprecationWarning: Implicit manager CMSPlugin.tree will be removed in django-mptt 0.6. Explicitly define a TreeManager() on your model to remove this warning.
DeprecationWarning
WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'.
Your choices after this are to restore from backups or rebuild via the `rebuild_index` command.
Are you sure you wish to continue? [y/N] y
Removing all documents from your index because you said so.
SearchBackendError: No fields were found in any search_indexes. Please correct this before attempting to search.
I have been searching for a solution but the results seem rather outdated. Any help please?
UPDATE:
Django - 1.5.5 - active
Whoosh - 2.5.4 - active
django-haystack - 2.1.0 - active
The haystack module looks for a file named search_indexes
so it will not find your indexes
module without altering the default behavior.