django oscar rebuild_index,错误

时间:2017-06-01 16:02:23

标签: django solr django-haystack django-oscar

  

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] unknown field'proizvoditel']

仪表板中的

我的产品类型的属性名为Producer,代码为proizvoditel

我替换了proizvoditel - > proizvoditel_s和rebuild_index没问题,但搜索不起作用。

1 个答案:

答案 0 :(得分:0)

如果您收到未知字段错误,可能是因为您尝试引入尚未在架构中注册的字段。

您使用的是什么版本的Django-Oscar和Solr?我使用的是Oscar 1.5和Solr 4.7.2,因此您的设置可能会略有不同。

如果您在bash中运行以下内容(假设您正在关注奥斯卡文档),则应解决您的字段问题:

$ python manage.py build_solr_schema > solr-4.7.2/example/solr/collection1/conf/schema.xml

如果您有自己的Solr设置,请自行运行build_solr_scema并将文件复制到solr的conf目录中。

确保重新启动服务器。然后做:

$ python manage.py rebuild_index --noinput

看看是否有帮助。

相关问题