Reputation: 25
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
After that i have an error:
Failed to add documents to Solr: Solr responded with an error (HTTP 400): [Reason: ERROR: [doc=catalogue.product.1451] unknown field 'proizvoditel']
in dashboard i have product type with attribute named Producer
with code proizvoditel
I replaced proizvoditel
-> proizvoditel_s
and rebuild_index is ok, but search not works.
Upvotes: 0
Views: 309
Reputation: 51
If you're getting an unknown field error it's probably due to a field you're trying to introduce that's not yet registered in the schema.
What version of Django-Oscar and Solr are you using? I'm using Oscar 1.5 with Solr 4.7.2, so there might be a slight variation with your setup.
If you run the following (assuming you're following the Oscar docs) in bash it should resolve your field problem:
$ python manage.py build_solr_schema > solr-4.7.2/example/solr/collection1/conf/schema.xml
If you have your own Solr setup, then run build_solr_scema
by itself and copy the file into your solr's conf directory.
Make sure you restart the server. Then do:
$ python manage.py rebuild_index --noinput
See if that helps.
Upvotes: 0