I want to show rating and price range in facet search however the rating is 
not displayed and price range is displayed but is disabled. What else 
should i have to do to show them in facet search? 

Here is the configuration

    'fields': OrderedDict([
        ('product_class', {'name': _('Type'), 'field': 'product_class'}),
        ('rating', {'name': _('Rating'), 'field': 'rating'}),
    'queries': OrderedDict([
             'name': _('Price range'),
             'field': 'price',
             'queries': [
                 # This is a list of (name, query) tuples where the name 
                 # be displayed on the front-end.
                 (_('0 to 20000'), u'[0 TO 20000]'),
                 (_('20000 to 40000'), u'[20000 TO 40000]'),
                 (_('40000 to 60000'), u'[40000 TO 60000]'),
                 (_('60000+'), u'[60000 TO *]'),

class ProductIndex(indexes.SearchIndex, indexes.Indexable):
    # Search text
    text = indexes.CharField(
        document=True, use_template=True,

    name = indexes.EdgeNgramField(model_attr='name', null=True)
    name_exact = indexes.CharField(model_attr='name', null=True, indexed=

    # Fields for faceting
    product_class = indexes.CharField(null=True, faceted=True)
    category = indexes.MultiValueField(null=True, faceted=True)
    price = indexes.FloatField(null=True, faceted=True)
    num_in_stock = indexes.IntegerField(null=True, faceted=True)
    rating = indexes.IntegerField(null=True, faceted=True)

    # Spelling suggestions
    suggestions = indexes.FacetCharField()

    date_created = indexes.DateTimeField(model_attr='created_at')
    date_updated = indexes.DateTimeField(model_attr='updated_at')

    _strategy = None

    def get_model(self):
        return get_model('catalogue', 'Product')

    def index_queryset(self, using=None):
        # Only index browsable products (not each individual child product)
        return self.get_model().browsable.order_by('-date_updated')

    def read_queryset(self, using=None):
        return self.get_model().browsable.base_queryset()

    def prepare_product_class(self, obj):
        return obj.get_product_class().name

    def prepare_category(self, obj):
        categories = obj.categories.all()
        if len(categories) > 0:
            return [category.full_name for category in categories]

    # def prepare_rating(self, obj):
    #     if obj.rating is not None:
    #         return int(obj.rating)

    # Pricing and stock is tricky as it can vary per customer.  However, the
    # most common case is for customers to see the same prices and stock 
    # and so we implement that case here.

    def get_strategy(self):
        if not self._strategy:
            self._strategy = Selector().strategy()
        return self._strategy

    def prepare_price(self, obj):
        strategy = self.get_strategy()
        result = None
        if obj.is_parent:
            result = strategy.fetch_for_parent(obj)
        elif obj.has_stockrecords:
            result = strategy.fetch_for_product(obj)

        if result:
            if result.price.is_tax_known:
                return result.price.incl_tax
            return result.price.excl_tax

    def prepare_num_in_stock(self, obj):
        strategy = self.get_strategy()
        if obj.is_parent:
            # Don't return a stock level for parent products
            return None
        elif obj.has_stockrecords:
            result = strategy.fetch_for_product(obj)
            return result.stockrecord.net_stock_level

    def prepare(self, obj):
        prepared_data = super(ProductIndex, self).prepare(obj)

        # We use Haystack's dynamic fields to ensure that the title field 
        # for sorting is of type "string'.
        if is_solr_supported():
            prepared_data['name_s'] = prepared_data['name']

        # Use title to for spelling suggestions
        prepared_data['suggestions'] = prepared_data['text']

        return prepared_data


Only the product_class works for now. Can anyone from the community help me 
at this, please?

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+unsubscr...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-oscar.
To view this discussion on the web, visit 
For more options, visit https://groups.google.com/d/optout.

Reply via email to