Extend ProductIndex in search_indexes.py

瀏覽次數:404 次
跳到第一則未讀訊息

ad...@philippundhee.ch

未讀,
2013年2月26日 上午9:14:522013/2/26
收件者: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

未讀,
2013年2月26日 下午4:16:132013/2/26
收件者: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

未讀,
2013年2月27日 清晨5:25:562013/2/27
收件者: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

未讀,
2013年3月12日 凌晨4:35:302013/3/12
收件者:django...@googlegroups.com、david.win...@tangentlabs.co.uk
Cool thank you very much for the answer. Helped me a lot.

Anentropic

未讀,
2015年6月6日 下午1:00:332015/6/6
收件者: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

未讀,
2019年3月27日 清晨5:51:302019/3/27
收件者: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

未讀,
2020年2月20日 下午2:07:502020/2/20
收件者: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 написал:
回覆所有人
回覆作者
轉寄
0 則新訊息