Question

I have a userprofile search index, like so:

class UserProfileIndex(SearchIndex, Indexable):
    text = CharField(document=True, use_template=True)
    last_name = CharField(model_attr='last_name', indexed=True)
    country = CharField(model_attr='country')
    sectors = CharField(use_template=True)
    services = CharField(use_template=True)

    def get_model(self):
        return UserProfile

    def index_queryset(self, using=None):
        """
        Used when the entire index for model is updated."""
        return self.get_model().public.all()

and I am trying to sort by the last_name field using this command:

s = SearchQuerySet().all().order_by('last_name')

I then get back:

Exception: No column for field 'last_name'

I have no problems doing a filter on that field.

s = SearchQuerySet().filter(last_name='Smith')

works fine.

I'm guessing this is a Whoosh issue, but I can't seem to find a work around.

Was it helpful?

Solution

Not sure if you've solved this but for the sake of anyone else who comes across this, I had the same issue and just figured it out.

If you use order_by on a field in Haystack and Whoosh is your back-end, the field you are ordering by must exist on ALL of your indexes. Not just the one you're interested in. Filter doesn't suffer from this same requirement, which is why that query goes through.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top