question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

price and rating not working in facet search

See original GitHub issue

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


FURNITURE_SEARCH_FACETS = {
    'fields': OrderedDict([
        ('product_class', {'name': _('Type'), 'field': 'product_class'}),
        ('rating', {'name': _('Rating'), 'field': 'rating'}),
        
    ]),
    'queries': OrderedDict([
        ('price_range',
         {
             'name': _('Price range'),
             'field': 'price',
             'queries': [
                 # This is a list of (name, query) tuples where the name will
                 # 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,
        template_name='search/indexes/product/item_text.txt')


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


    # 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 levels
    # 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 used
        # 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

here is the ui

Image of facetsearch

I have both the rating and price as in source code of django-oscar but it is not working to me.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
okfishcommented, Mar 15, 2018

Did you read the docs? Maybe, you are using your own fork of repo? There is no any reference to your settings in the core framework, but OSCAR_SEARCH_FACETS is

0reactions
solarissmokecommented, Mar 17, 2018

I’m going to close this because (a) providing support for a codebase that you’ve forked and modified is quite difficult - if there is a bug introduced by the changes you made then we’re not in a position to track it down and (b) we’re soon replacing the existing search functionality to drop dependency on Haystack (#2606) - so this issue is not likely to get much attention in the mean time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

show price and rating in facet search - django - Stack Overflow
I want to show rating and price range in facet search however the rating is not displayed and price range is displayed but...
Read more >
Faceted Search: An Overview - Algolia
Unlike facets, filters do not change between searches. In clothing stores, for example, ... Category; Color; Price range; Size; Rating; Age.
Read more >
Star Rating - FacetWP
Overview. The Star Rating facet type allows users to filter by average rating. ... This average rating field must contain a numeric value...
Read more >
Faceted Search with Solr - Lucidworks
Examples and tutorial on how to implement faceted search queries in Apache Solr. ... However, we want price ranges, not individual prices.
Read more >
Facet Search: The Most Comprehensive Guide. Best Practices ...
For parallel selection, you can face the problem of dependent facets. Some combinations of the facet values would return no results, and you ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found