Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9194831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:30:18+00:00 2026-06-17T21:30:18+00:00

I am trying to see if the django-haystack is good for my faceting needs.

  • 0

I am trying to see if the django-haystack is good for my faceting needs. Currently I want to display number near my facets. Lets say we have a model shown in their docs, but with an extra field for faceting (e.g. style in which author writes notes… e.g. styles are classic or modern). So index will look like this.

class NoteIndex(SearchIndex, indexes.Indexable):
    text = CharField(document=True, use_template=True)
    author = CharField(model_attr='user', faceted=True)
    style = CharField(model_attr='style', faceted=True)
    pub_date = DateTimeField(model_attr='pub_date')

Now I make a search query set, and narrowing to facet author e.g. john. Now I want to display estimation on how many products will appear if I will select another author together with John (e.g. +10 articles). Also same question about adding an extra facet from styles… How do I do this. Search BE is elasticsearch.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:30:19+00:00Added an answer on June 17, 2026 at 9:30 pm

    The facet_counts method of SearchQuerySet does what you want:

    results = SearchQuerySet().filter(text='some product').facet('author')
    counts = results.facet_counts()
    author_results = counts['fields']['author']
    author_counts = {author: num_products for author, num_products in author_results}
    

    Then, you can sum up the number of products by John and the number of products by another author. That will give you the number of products if you were to broaden the search to both of them:

    num_john_products = author_counts.get('John', 0)
    num_bob_products = author_counts.get('Bob', 0)
    total = num_john_products + num_bob_products
    

    Or, you could even find the author other than John with the most products, and show the number of results if you were to also include that author in the search:

    author_counts.pop('John')
    most_popular_author = max([(count, author) for author, count in author_counts])
    count, author = most_popular_author
    total_john_and_most_popular = num_john_products + count
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to show thumbnail images in Django admin, but I can only see
I' m trying to build a Django TemplateLoader, but I can't make it 'see'
I'm trying to upload videos from django admin, but I can't see how to
I'm trying to see the Authorization header in Django, using mod_wsgi. I read that
I'm trying to get the Django Admin interface to display information about my profile.
I'm trying to make a custom search form using django haystack, i just modify
I'm trying to use django-taggit ( see ). This is what I have in
Iam new to django-haystack, and I am trying to follow the getting started guide.
I am trying to see if the user has internet connection when the app
I'm trying to see if there is a way in rails routing to 'return'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.