Facet search by attribute values

1,259 views
Skip to first unread message

Денис Насыров

unread,
Sep 22, 2014, 10:17:27 AM9/22/14
to django...@googlegroups.com
Hi everyone.
I am  trying to create my own store, and I met one problem.
I want to filter products by attributes value, ex: country, weight, etc.
I tried to change settings:
1. Iadded country attribute for product class Fruit. 
2. I change settings,
OSCAR_SEARCH_FACETS = {
    'fields': {
        # The key for these dicts will be used when passing facet data
        # to the template. Same for the 'queries' dict below.
        'country': {
            'name': "country",
            'field': 'country'
        }
    },
    'queries': {

    }
}
3. I executed rebuild_index.
But, it didn't work.
Could you please describe what is wrong?


David Winterbottom

unread,
Sep 22, 2014, 4:41:13 PM9/22/14
to django-oscar
​There's a few things you need to do to facet on a new field:
  • Ensure your Solr schema has this new field included with faceted=True.
  • Ensure your search_indexes.py feeds the correct data to Solr
  • Ensure Oscar's search form makes the appropriate query to Solr - using the OSCAR_SEARCH_FACETS should do this for you but it's worth checking it if things aren't working as expected.
As you can see, search can get quite complicated. Good luck.

 


--
https://github.com/tangentlabs/django-oscar
http://django-oscar.readthedocs.org/en/latest/
https://twitter.com/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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-oscar/0bb062fd-1b35-41c4-ad50-4750d691b959%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
David Winterbottom
Technical Director

Tangent Snowball
84-86 Great Portland Street
London W1W 7NR
England, UK

Kishan Mehta

unread,
Sep 22, 2015, 2:48:57 AM9/22/15
to django-oscar, david.win...@tangentlabs.co.uk
I am also implementing similar funcionality. Can we go filering by facted search ? Because search and filtering is different requirement I think ,
Sorry for I am new to oscar.

Rosen Pashov

unread,
Mar 18, 2016, 10:17:20 AM3/18/16
to django-oscar
Hello,
I'm building an ecommerce website with django-oscar and It is a great oscommerce platform but I am struggling to achieve facet filtering by product attribute.
I think I am very close, but despite I've gone trough all the documentation I think it is not clearly explained how to add facet filter by attribute.

I've successfully setup Solr and I have both default facet filters showing up on the frontend (Type and Price range)

What I have done already is that I've added :

     <field name="product_attribute_value" type="text_en" indexed="true" stored="true" multiValued="true" />

to my Solr schema.xml

then I have added:

    product_attribute_value = indexes.MultiValueField(null=True, faceted=True)

to my search_indexes.py

and then I've added:

        ('product_attribute_value', {'name': ('Marka'), 'field': 'product_attribute_value'}),

to OSCAR_SEARCH_FACETS in my settings.py

After that Solr is throwing an error:

ERROR org.apache.solr.core.SolrCore  – org.apache.solr.common.SolrException: undefined field: "product_attribute_value_exact"

I've tried to add this field to schema.xml, search_indexes.py and to OSCAR_SEARCH_FACETS, but the error remains.

I know I am very close, but most probably i've mistaken the field type or something and I am stuck. Please help me to add a facet filter by product attribute.

My catalogue looks like that:
I have only one product type with only one product attribute, and that product attribute is of type "option" with an option group with a few options.
I want customers to be able to filter products by that attribute.
It is something like that product type - "Part", product attribute - "Carmake", option group - "Carmakes" with options "VW", "Audi", "BMW"

So when the customer gets to the product list of a category all products in that category are displayed, I want them to be able to filter products by facet filter that filters all Parts according to the Carmake.





Jhovel

unread,
Aug 5, 2018, 2:52:12 AM8/5/18
to django-oscar
Hello Mates,

I know it's late but I'm hoping that I can help someone with this snippet on how I successfully added Product attributes as part of facets.

I'm using a search backend solr.



First thing first modified your search_indexes.py to have a new field that will show as part of facets like this.

# Product attributes
attribute = indexes.MultiValueField(null=True, faceted=True)

def prepare_attribute(self, obj):
attribute_values = obj.attribute_values.all() # getting the list of atrribute values related to a product
if len(attribute_values) > 0:
values = []
for attribute_value in attribute_values: # Loop over the list of attribute values
for option in attribute_value.value: # Loop over the list of value list that contain the value of the attribute
values.append(option.option) # then append the value to a existing list to be return for the function

return values
 

And after that all you need to to do is add it in your OSCAR_SEARCH_FACETS  and build a new schema and update restart your server. 

I hope this will help someone out there who have the same challenge as me. 

pythan

unread,
Apr 9, 2019, 12:31:46 PM4/9/19
to django-oscar
Hey, i am getting confused about this.

Could you write me an example for attribut: "test" or for model.product.test? 
test = models.IntegerField()
Reply all
Reply to author
Forward
0 new messages