【发布时间】:2017-06-01 16:02:22
【问题描述】:
apps.search.search_indexes.py
class ProductIndex(search_indexes.ProductIndex):
def index_queryset(self, using=None):
return super(ProductIndex, self).index_queryset().exclude(categories=None)
def read_queryset(self, using=None):
return super(ProductIndex, self).read_queryset().exclude(categories=None)
def prepare(self, obj):
prepared_data = super(ProductIndex, self).prepare(obj)
attrs = defaultdict(set)
attrs_from_obj = lambda obj: [attrs[attr.attribute.code].add(attr.value) for attr in obj.attr.get_values()]
if obj.is_parent:
for child in obj.children.all():
attrs_from_obj(child)
else:
attrs_from_obj(obj)
for attr, vals in attrs.items():
prepared_data[attr] = list(vals)
return prepared_data
./manage_py rebuild_indexes --noinput
之后我有一个错误:
无法将文档添加到 Solr:Solr 响应错误 (HTTP 400):[原因:错误:[doc=catalogue.product.1451] 未知字段 'proizvoditel']
在仪表板中,我的产品类型的属性名为 Producer,代码为 proizvoditel
我替换了proizvoditel -> proizvoditel_s 并且rebuild_index 没问题,但搜索不起作用。
【问题讨论】:
-
能否展示相关代码,例如模型、视图等
-
添加更多详细信息以便我们提供帮助。
标签: django solr django-haystack django-oscar