Extend ProductIndex in search_indexes.py

404 views
Skip to first unread message

ad...@philippundhee.ch

unread,
Feb 26, 2013, 9:14:52 AM2/26/13
to django...@googlegroups.com
Hi there
What would be the best approach to extend the given ProductIndex in the search/search_indexex.py?
Just extending ends in an error:
Model '<class 'oscar.apps.catalogue.models.Product'>' has more than one 'SearchIndex`` handling it.

Could anyone give me a short template how the overridden search app could look like?

Thank you very much.
Regards Andras

Jonathan Moss

unread,
Feb 26, 2013, 4:16:13 PM2/26/13
to django...@googlegroups.com
Hey Andras,

Yay, one I can help with although the credit really needs to go to
Sebastian who solved the issue when we came across it.

The issue stems from Haystack finding both the search_index in Oscar
itself and the one you have written that extends it. So all you really
need to do is tell haystack to ignore the one in Oscar.

So lets assume you new search_index is in myproject.search.search_index
and looks something like this:

from haystack import indexes
from oscar.apps.search.search_indexes import ProductIndex as
CoreProductIndex


class ProductIndex(CoreProductIndex):
brand = indexes.CharField(model_attr="brand", faceted=True)
# Other index field etc.


Within you settings file where you define the haystack config you need
to do the following:

# Haystack settings
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
'EXCLUDED_INDEXES':
['myproject.search.search_indexes.CoreProductIndex',]
},
}

This informs Haystack to exclude the search_index pulled in from Oscar.

Hope that helps.

Regards,
Jon
> --
> https://github.com/tangentlabs/django-oscar
> ---
> You received this message because you are subscribed to the Google
> Groups "django-oscar" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-oscar...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-oscar?hl=en-US.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>


--
Jonathan Moss
Director

Tangent Snowball Australia Pty
Suite 109
175 Sturt Street
Melbourne, VIC 3006
ABN: 76 137 883 615

T: +61 (0) 3 9645 8796
M: +61 (0) 4 1525 1208
E: jonath...@tangentsnowball.com.au

David Winterbottom

unread,
Feb 27, 2013, 5:25:56 AM2/27/13
to django-oscar
Great answer Jon - thanks.

Just wanted to note that Oscar's treatment of search is going to a focus for v0.6.  It's possible/likely that some sweeping improvements will be made.
David Winterbottom
Head of Programming

Tangent Labs
84-86 Great Portland Street
London W1W 7NR
England, UK

ad...@philippundhee.ch

unread,
Mar 12, 2013, 4:35:30 AM3/12/13
to django...@googlegroups.com, david.win...@tangentlabs.co.uk
Cool thank you very much for the answer. Helped me a lot.

Anentropic

unread,
Jun 6, 2015, 1:00:33 PM6/6/15
to django...@googlegroups.com
This would good info for the docs

To clarify one part below, you have to exclude *both* possible class paths for the base ProductIndex if you extended it, eg:

# Haystack settings 
HAYSTACK_CONNECTIONS = { 
    'default': { 
        'ENGINE': 'haystack.backends.simple_backend.SimpleEngine', 
        'EXCLUDED_INDEXES': [
            'myproject.search.search_indexes.CoreProductIndex',
            'oscar.apps.search.search_indexes.ProductIndex',
        ] 
    }, 

Ehmad Zubair

unread,
Mar 27, 2019, 5:51:30 AM3/27/19
to django-oscar
I'm still having trouble getting this to work. Do you mean we have to exclude Oscar's ProductIndex ('oscar.apps.search.search_indexes.ProductIndex') OR our extended ProductIndex? 

When i add 'oscar.apps.search.search_indexes.ProductIndex' to the EXCLUDED_INDEXES, the error still pops up.

Amster Am5ter

unread,
Feb 20, 2020, 2:07:50 PM2/20/20
to django-oscar
Im new here, dont know what is better to go with new post or continue existing. Choosing second.
So, I have same error when forking search app. In my case its impossible to EXCLUDED_INDEXES [oscar.apps.search.search_indexes.ProductIndex, apps.search.search_indexes.ProductIndex]
Is anybody solve the issue?

Best regards, Alex

вторник, 26 февраля 2013 г., 15:14:52 UTC+1 пользователь ad...@philippundhee.ch написал:
Reply all
Reply to author
Forward
0 new messages