【问题标题】:django oscar rebuild_index with errordjango oscar rebuild_index 有错误
【发布时间】: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


【解决方案1】:

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

您使用的是哪个版本的 Django-Oscar 和 Solr?我将 Oscar 1.5 与 Solr 4.7.2 一起使用,因此您的设置可能会略有不同。

如果您在 bash 中运行以下命令(假设您遵循 Oscar 文档),它应该可以解决您的字段问题:

$ 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

看看有没有帮助。

【讨论】:

    猜你喜欢
    • 2015-04-02
    • 1970-01-01
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 2014-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多