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 8102639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:17:36+00:00 2026-06-05T23:17:36+00:00

Let’s say I have 3 models (Note, Comment, Article) that I want to search

  • 0

Let’s say I have 3 models (Note, Comment, Article) that I want to search using django-haystack and I setup 3 indexes like this.

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

class CommentIndex(SearchIndex):
    text = CharField(document=True, use_template=True)
    author = CharField(model_attr='user', faceted=True)
    pub_date = DateTimeField(model_attr='pub_date')

class ArticleIndex(SearchIndex):
    text = CharField(document=True, use_template=True)
    author = CharField(model_attr='user', faceted=True)
    pub_date = DateTimeField(model_attr='pub_date')

When I get my results, I’m able to use the author facet to show the number of results by author.

>>> from haystack.query import SearchQuerySet
>>> sqs = SearchQuerySet().facet('author')
>>> sqs.facet_counts()
{
    'dates': {},
    'fields': {
        'author': [
            ('john', 4),
            ('daniel', 2),
            ('sally', 1),
            ('terry', 1),
        ],
    },
    'queries': {}
}

But how can I find out how many results by Model type? For example.

Notes: 4
Comment: 2
Article: 1

Ideally I would like to filter on it, like a normal facet. I’m using the FacetedModelSearchForm now, and I can see the model types, just can’t get the count values. Is this possible? If so, how?

Similar Questions:

It looks like someone else asked this question as well, but maybe didn’t ask the question clear enough.

Django Haystack faceting on the model type

This one is similar but they just want to order by the content type, I want the count by content type.

Using django-haystack, how do I order results by content type

Here is another similar question, but not quite the same, and once again no answer as well.

Django Haystack Faceting examples

  • 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-05T23:17:38+00:00Added an answer on June 5, 2026 at 11:17 pm

    Have you tried just creating another facet for that? The only potentially difficult part would be getting the model name. Most likley, you would want to use verbose_name so it’s more readable, which you can get from _meta.verbose_name. However, something like the following code probably wouldn’t work:

    model = CharField(model_attr='_meta.verbose_name', faceted=True)
    

    So, you could simply add a method to your model to just return this value:

    def get_model_name(self):
        return self._meta.verbose_name
    

    Then:

    model = CharField(model_attr='get_model_name', faceted=True)
    

    All of this is untested though, as I’ve never needed to do this myself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I want to have some kind of a cache that did something
Let's say I have a structure named vertex with a method that adds two
Let's say I have an facebook application running using the JS SDK. First user
Let's say I have multiple requirements for a password. The first is that the
Let's say that I have a date in R and it's formatted as follows.
Let's say you have a method that expects a numerical value as an argument.
Let's say I have a bunch of links that share a click event: <a
Let's say that I have a set of relations that looks like this: relations
Let's say I have a dataset, which can be neatly classified using weka's J48
Let's say I have the following function in C#: void ProcessResults() { using (FormProgress

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.