1

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.

Stuart Marsh
  • 241
  • 2
  • 9

1 Answers1

2

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.

pbaehr
  • 622
  • 1
  • 5
  • 11
  • Thanks for this. That is an odd requirement though, especially as I have about 15 different indexes in the project I'm working on. I ended up moving from Whoosh and switching to Elastic Search as a backend instead. Seems to have less of these types of problems. The other one I found was Whoosh won't let you use the .model() syntax, you have to use filter(django_ct='') instead. – Stuart Marsh Oct 24 '13 at 20:38
  • I was about to switch to Elastic Search when I discovered this and just finished the project. I do feel like I hit Whoosh's limits very quickly with pretty basic queries. I'd run up against the .model limitation, as well. If I extend my project further I'll almost certainly switch before I continue. – pbaehr Oct 27 '13 at 14:37