Reputation: 2276
I am using Haystack in one app and its perfect. It is indexing everything that I need. But, now I created another app, with different model and content, and I would like to Haystack index it. The idea is to create two different "search" links on my website, one for each app.
However, when I add the second configuration to haystack index it, I get some problem...
I created a new search_index.py (inside my new app) with the following content:
import datetime
from haystack.indexes import *
from haystack import site
from oportunity.models import Oportunity
class OportunityIndex(SearchIndex):
title = CharField(document=True, use_template=True)
body = CharField()
date= DateTimeField()
def index_queryset(self):
return Oportunity.objects.filter(date=datetime.datetime.now())
site.register(Oportunity, OportunityIndex)
but, when I run python manage.py rebuild_index I get the following error:
line 94, in all_searchfields raise SearchFieldError("All SearchIndex fields with 'document=True' must use the same fieldname.") haystack.exceptions.SearchFieldError: All SearchIndex fields with 'document=True' must use the same fieldname.
Upvotes: 4
Views: 1156
Reputation: 11888
This is a known limitation of Haystack which has been discussed in a few different places where the underlying document store needs the document field to be consistently named across all search models.
It is documented in the haystack docs what the recommended document field name is. Bottom line, you can't define title = CharField(document=True)
on one index and content = CharField(document=True)
on another index, they have to be named the same.
BEST PRACTICE: name the index field text
. This is recommended by the haystack docs and will give you the most compatibility with 3rd party apps.
Upvotes: 5