multiple searchindexes with haystack

8 views
Skip to first unread message

captainmish

unread,
Feb 21, 2011, 8:19:52 AM2/21/11
to django-page-cms
Hi

I need to add a "knowledgebase" to an existing gerbi site, and would
like to do it without any wheel reinvention. I think gerbi will be
fine for creating kb items, but I'm stuck on how to integrate haystack
with this.

Haystack currently indexes pages, and this works fine, but there are
likely to be hundreds of kb items that I'd like to keep separate from
"normal" pages. I have the list of kb pages from
kb_root_page.get_children_for_frontend(), but not sure how to get
these into their own searchindex. It seems that haystack does not
allow multiple indexes for a single model, so possibly I would need to
subclass Page, though not sure how messy this would become. Ive seen
another recommendation to add a searchindex field like a_or_b as well,
and then filter results based on this.

Has anyone managed to differentiate search results between content in
the same model? Any tips welcome!

Thanks,

captainmish

unread,
Feb 21, 2011, 10:40:26 AM2/21/11
to django-page-cms
In case its useful to anyone else, I have got around this with an
extra boolean field in the SearchIndex. The searchindex can get a
prepare_FIELDNAME method, which I then used to set this field to True
or False based on the type of page. After this,
haystack.views.basic_search almost does the job of searching, just
adding a filter(is_kb="True") to the results here gives me the items I
want (or False for excluding them). I copied basic_search into
localsite.views, edited to change this filter, and everything seems to
work well.

The only change to pages is the searchindex to add this field - I
thought about unregistering this in my local app, then reregistering,
but was worried about timing - would it be possible for my call to
unregister to happen before the pages searchindex is registered?
Reply all
Reply to author
Forward
0 new messages